andrew_reece
andrew_reece

Reputation: 21264

Reference Qualtrics embedded data field containing dot (.) character

When importing fields from a Contacts List, corresponding embedded data fields include dots (.). For example, here's the name of one embedded data that gets automatically created on Contact List import:

result.elements.0.embeddedData.V1

In my survey, I want to access the value stored in this embedded data field. But the getEmbeddedData() javascript method that Qualtrics provides apparently doesn't like dots.
For a simpler example, I shortened the above embedded data name to V.1:

Qualtrics.SurveyEngine.getEmbeddedData('V.1'); // returns null

and a null value is returned.

If I change the embedded data field name to V1 (no .), then the method returns the correct value:

Qualtrics.SurveyEngine.getEmbeddedData('V1'); # returns correct value

In the case where there's a dot in the name, I tried escaping with \\ and \, like: getEmbeddedData('V\\.1'), but both of those escape styles don't work - null is returned.

There is another syntax to access embedded data with javascript - the "${e://Field/myfield}" approach - but I need to be able to set the last character (i.e. the number after V) dynamically, and this method doesn't allow for that. Specifically, for embedded data V1:

var ix = 1;
Qualtrics.SurveyEngine.getEmbeddedData('V'+ix); <-- this works
"${e://Field/V"+ix+"}"; <-- this doesn't work

I have over 1000 fields that get imported from this contact list, so I don't want to rename each one by hand to remove the dots. It seems weird that Qualtrics would pick this naming schema as an import default if it breaks one of its own methods - am I doing something wrong here? Is there an alternate syntax I can use?

Upvotes: 1

Views: 858

Answers (1)

T. Gibbons
T. Gibbons

Reputation: 5004

I answered your related question on the Qualtrics Community. You can't do "${e://Field/V"+ix+"}" because pipes are resolved on the server before the page is sent to the browser.

When a web service returns json or xml, by default Qualtrics uses a dot for each level in structure. You can override this by changing the embedded variables (on the left in the web service block) to names without dots.

Another alternative would be to write your own web service script that calls the Qualtrics API, then puts the results in a flat json structure before returning them to your survey.

Update based on comments below

Automatically renaming embedded variables returned from a web service call - I think the only way to do that is my alternative suggestion - write your own web service script that converts the info returned from the api and renames the variables putting them in a one dimensional associative array, then convert that array to json.

Qualtrics Question API - getEmbeddedData() has been removed from the documentation. I don't know why, and would have to ask Qualtrics Support. For now, it still works. So, if you need to construct embedded variable names with a dot dynamically, you could create your own function based off getEmbeddedData(). Use your browser's developer tools to see what it does.

I've found addEmbeddedData() to be useless in actual practice. setEmbeddedData() works whether the embedded data field is defined in the survey flow or not. If it is defined in the survey flow, it gets saved to the response data. If it is not defined in the survey flow, it can be referenced throughout the current survey response, but it won't be saved in the response data.

Upvotes: 1

Related Questions