Code Task Error Help | XM Community
Skip to main content

Hi everyone!

I have a Workflow with a Code Task that was running fine this morning.

But now I am getting an error: “SyntaxError: Invalid or unexpected token”

I don’t think it is related to my code because it works with another workflow.

 

Any idea how I can fix it?

 

 


 

Are you piping in values that might contain quotes or something like that?


Are you piping in values that might contain quotes or something like that?

Yeah but this is in a loop and some of them do not have quotes and are still failing.


 

Are you piping in values that might contain quotes or something like that?

Yeah but this is in a loop and some of them do not have quotes and are still failing.

I think my issue is that because I am piping in an open-ended value, some of them have breaklines.

Is there a way I can remove the breakline before it gets called by my workflow? 


Hi,

Depending on the type of workflow and where/how it’s getting its data, you could use a code task or a basic transform task to remove line breaks with a regular expression.


For example, you could transform the text coming from a open-ended question before using it.

function codeTask() {

var inputText = `${q://QID1/ChoiceGroup/SelectedChoicesTextEntry}`;
var outputText = text.replace(/(\r\n|\n|\r)/g, '');

return {
result: outputText
};
}

 


For example, you could transform the text coming from a open-ended question before using it.

function codeTask() {

var inputText = `${q://QID1/ChoiceGroup/SelectedChoicesTextEntry}`;
var outputText = text.replace(/(\r\n|\n|\r)/g, '');

return {
result: outputText
};
}

 

Thanks Vincent! I have tried but I still get an error. I think Qualtrics can’t load it in the ‘inputText’ variable at all because of the whitespace/breaklines.


You might need to clean your input before then. A bit hard to help you without knowing where it’s coming from.

If it’s coming from a survey response, you could clean it there with custom js in a question.

If it’s coming from a file in an ETL workflow, maybe you can use a transform task to clean it with a regex before processing it in the code task.


You might need to clean your input before then. A bit hard to help you without knowing where it’s coming from.

If it’s coming from a survey response, you could clean it there with custom js in a question.

If it’s coming from a file in an ETL workflow, maybe you can use a transform task to clean it with a regex before processing it in the code task.

Thank you! I think that worked out - I used a transform task before my code.


Leave a Reply