How to add a JavaScript code to my workflow? | XM Community
Skip to main content

Hello everyone,

I am looking for help to make this task code work in my workflow. Essentially, I would like to convert one of the embedded field (ARR) to a number format. As of now, the value that comes from this field in SFDC is getting displayed as a plain number (no decimals or thousands 111,222).

 

This is the code I built, but when adding to the slack notification, I dont get any result. Any thoughts here?

 


const ARR = ${e://Field/ARR};

function codeTask(ARR) {
   
    const numberARR = Number(ARR);

 
    return {
        result: numberARR
    };
}


const result = codeTask(ARR);

You’re getting that result because that’s how JS stores numbers. To get the desired results, you’ll need to format the number:

const number = 123456.789;
const frm1 = new Intl.NumberFormat("en-US", { maximumSignificantDigits: 21 }).format(number);
const frm2 = new Intl.NumberFormat("en-IN", { maximumSignificantDigits: 21 }).format(number);

// Output
// frm1 = "123,456.789"
// frm2 = "1,23,456.789"

 


@ahmedA What would the final version of this code look like this? (Sorry I do not code and very new into JavaScript syntax)

 


function codeTask() {
const ARR = "${e://Field/ARR}";
const numberARR = Number(ARR);
const formattedARR = new Intl.NumberFormat("en-IN", { maximumSignificantDigits: 21 }).format(numberARR);

return {
formattedARR
};
}

This will store and embedded data called formattedARR for later use.


Thank you @ahmedA the code was validated , but the output in the Slack message is still showing as blank. 


I’m sorry, but there could be lots of things that are going wrong, and guessing at my end would take hours, most of them fruitless.

You’ll first need to narrow down the scope of the problem.

Open your workflow run history and see where it is failing.

If its not, then see the output being generated the code. If this is invalid, look at the input and output to see if they match your expectations. If its valid, look at the input and output of the slack step.

If the input in invalid, take a look at your slack config to ensure you are capturing the correct variables. If the output is invalid, you’ll need to take it up with Qualtrics. If the output is valid, you’ll need to take it up with your Slack Admin.

 

As a sanity check, instead of slack, try sending  it to an email instead of slack, since the json is smaller, you’ll spend less time figuring out whether the variables are being sent or not.


@ahmedA thank you , I sent to my email and the output worked, just need to understand why this is not working in Slack.


@ahmedA just want to confirm that it worked now on my end. I appreciate your help here. 


Leave a Reply