3

In my survey, I need to show several different links to a few respondents, were each respondent is assigned 20+ unique links.

Essentially, I want to pipe the link into a survey question to dynamically display them to different respondents. I've been trying to match the observation IDs (“obsid") to the link stored as embedded data in the contact list (“link”) by creating a function that returns the matching link given an id (where I can populate the id by appending a query string to the URL of the survey link sent out to different respondents). I set this as a new embedded data field (‘matchlink') through JS and pipe this into a survey question as a clickable link.

In JS, I created a table (“ID_table") that calls the embedded data from the contact list. Then, the function getLookupTableByID() is used to match the this ID to the link value. This is adapted from https://thepoliticalmethodologist.com/2019/05/23/utilizing-javascript-in-qualtrics-for-survey-experimental-designs/ , where they’ve manually inputed values in the lookup table. Instead, I want to draw these values from a pre-defined embedded data label from a .csv file.

Below is my JavaScript. Then, I set the new embedded data field ‘matchlink’ at the top of the survey flow and leave the field empty.

var ID_table = {
  ID: "${e://Field/obsid}",
  link: "${e://Field/link}"
};

function getLookupTableByID(mytable, IDfield, ID, returnfield) {
  matchindex = null;
  try {
    //this matches the panel data observation ID (obsID) with the row ID (ID) variable in the JS table above
    var matchindex = mytable[IDfield].indexOf(ID);
    //this returns the value of the response (defined in JS table) at the matching index
        var matchreturn = mytable[returnfield][matchindex];
  } catch (ex) {
    console.log(ex);
  }
  return matchreturn;
}


//get observation ID (obsid) from panel data
var obsID = Qualtrics.SurveyEngine.getEmbeddedData("obsid");


//create new Embedded Data field with this function that corresponds to the matched file to be shown
var match = getLookupTableByID(ID_table, "ID", obsID, "link");
    Qualtrics.SurveyEngine.setEmbeddedData('matchlink', match);


jQuery("#matchlink").html(ID_table.link);

However, when I go to pipe “matchlink" into the survey content as a hyperlink, it does not show up. I think it might have something to do with the HTML, but this is all new to me and I’m having trouble figuring out how to correctly display the link. It seems like what I want to do is similar to what has been done here: https://www.qualtrics.com/community/discussion/3530/how-to-save-the-embedded-data-in-the-csv-file-how-to-show-the-content-of-the-embedded-data-in-a-q

In the HTML, I have:

<div>Please click on <a href="${e://Field/matchlink}" target="_blank">this link</a> to view the article.&nbsp;</div><div>&nbsp;</div>

I’ve also tried this, but I’m certain this is improper formatting:

<div>Please click on <span>id="matchlink">this link</span> to view the article.&nbsp;</div><div>&nbsp;</div>

Any ideas on how to fix the code would be greatly appreciated! I’m also open to alternative approaches to accomplishing the larger task. Hope this is clear.

Thank you in advance!!

Annie Chen
  • 61
  • 7

0 Answers0