Can't identify source of "unexpected identifier" error that happens intermittently | XM Community
Skip to main content

I can't tell what the unexpected identifier is based on what qualtrics is giving me in the console. However, each time it happens, the error seems to come from the same line of code in one of the built in libraries. Here is the error info Qualtrics is giving me:
vendor.4336af1e4e0f1264707f.js:1 Failed to evaluate page script in page SyntaxError: Unexpected identifier
    at eval ()
    at https://jefferson.co1.qualtrics.com/jfe/static/dist/vendor.4336af1e4e0f1264707f.js:1:92606
    at Function.globalEval (https://jefferson.co1.qualtrics.com/jfe/static/dist/vendor.4336af1e4e0f1264707f.js:1:92617)
    at N (https://jefferson.co1.qualtrics.com/jfe/static/dist/vendor.4336af1e4e0f1264707f.js:1:82472)
    at yt.fn.init.append (https://jefferson.co1.qualtrics.com/jfe/static/dist/vendor.4336af1e4e0f1264707f.js:1:137986)
    at https://jefferson.co1.qualtrics.com/jfe/static/dist/jfe.aae0f22679e5e5820520.js:1:106354
    at r (https://jefferson.co1.qualtrics.com/jfe/static/dist/vendor.4336af1e4e0f1264707f.js:1:68838)
    at n._callHandler (https://jefferson.co1.qualtrics.com/jfe/static/dist/vendor.4336af1e4e0f1264707f.js:1:35971)
    at n._settlePromiseFromHandler (https://jefferson.co1.qualtrics.com/jfe/static/dist/vendor.4336af1e4e0f1264707f.js:1:36140)
    at n._settlePromiseAt (https://jefferson.co1.qualtrics.com/jfe/static/dist/vendor.4336af1e4e0f1264707f.js:1:38460) window.Q_CustomJSContextQID = "QID16";window.Q_CustomJSContextQID = "QID16";
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/


});


Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var topic = '"Emergency Department LARP"';
var description = '"Dress up like your favorite healthcare provider and perform real surgery in the ED! \\n\\nHave you ever wanted to live a day in another doctor's shoes? Try a new specialty on for size? This is the LARP for you!"';
var qualifications = '"*No experience necessary*\\n\\n*Must provide own saw*\\n\\n*All participants must sign a waiver in the event of accidental or deliberate death*"';

var messagePayload = {
response_id: "R_2TRUHCtoKEjiZFN",
Q_R: "", 
department: "Medicine", 
attending: "John Linton", 
email: "john.linton@jefferson.edu",
division: "Hospital Medicine", 
topic: topic.split('"') 1], 
project_description: description.split('"')n1], 
position_type:  "Nursing Student, Nurse, Medical Student, Medical Resident, Fellow, Other", 
qualifications: qualifications.split('"')s1]
};

var jsonPayload = JSON.stringify(messagePayload);

Qualtrics.SurveyEngine.setEmbeddedData("json", jsonPayload);
});


Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});


This is the line of code where the error is supposedly originating.
            "undefined" != typeof console && (consolent] && "debug" != t ? consolent].apply(console, i) : console.log.apply(console, i)),

It's maddening because some or most of the time, the same code works as it should. Certain inputs to the survey questions cause this unexpected identifier but I can't find the pattern.

I have found the issue. There was an apostrophe in the "description" string which is interpreted as a single quote.
I'm not exactly sure how I can use an embedded data field in my custom javascript code without adding an extra set of quotes around it thus breaking anything that I try to do with it. This solve with using single quotes seemed to be the ticket, but I guess not.
I suspect I will have to add code to escape single quotes/apostrophes in addition to using JSON.stringify on the user's input.


You could use a right apostrophe (doctor’s) instead of a regular apostrophe.


Is there some way of enforcing that with users who are entering text into these answer fields? I wouldn't even how to go about using one over the other in the normal survey UI. I wouldn't expect my users to.


I didn't realize it was user entered because in the example above you are defining it in the JS.
Anyway, you could do global replace of apostrophes with right apostrophes on any text entries fields in the addOnPageSubmit() function.


Thanks for the help and suggestions TomG! I'll figure something out.


Leave a Reply