Simple Javascript in Slack Workflow | XM Community
Skip to main content

Hello! I have a slack workflow set up and I am trying to create an automated weekly slack post within my set up Slack group that summarizes our overall average NPS plus the average % of Promoters, Passives, and Detractors. I have used the calculate metric to set up a workflow for average NPS and the count of Promoters, Passive,  & Detractors in the last 7 days, but cannot use it to create a “%” for those that are Promoters, Passive,  & Detractors.

 

My TAM has recommended I use the “code” task to write a simple javascript that says something like ::count of promotors in last 7 days:: / ::total count of surveys in last 7 days:: and have it add a “%” but they cannot write this javascript for me. I was wondering if any one could help me with what I should/could put in the code to do this. 

 

This is what the code in workflow looks like:

function codeTask() {

    return {
        result: ""
    }
}
 

An example of 1 of the count records that I can pipe in looks like: 

~{ch://OCAC_3koWZQxHi6nxxcr/sampleStats_count} -->> this is my total count for the last 7 days

 

I am very new to javascript so any help would be great, and double great would be help + some description to help me replicate.  I REALLY appreciate it!

@Aship An easier way is to make a Public Report and share that link to you Slack channel every week


Thank you so much @dxconnamnguyen. I actually have a dashboard that I will be linking, but the people in my organization really want to reference the scores within slack if feasible because they would like to tag people directly in in the slack channel on what they see. Leaving me to try to figure this out unfortunately.

 

Thank you so much for the recommendation/suggestion!


@Aship,

I don’t know what the field names are, but your calculation might look something like:

var result = Math.round((Number("{pipe numerator}")/Number("{pipe denominator}"))*100);

Then you would return result.


@Aship,

I don’t know what the field names are, but your calculation might look something like:

var result = Math.round((Number("{pipe numerator}")/Number("{pipe denominator}"))*100);

Then you would return result.

I realized I forgot the %:

var result = Math.round((Number("{pipe numerator}")/Number("{pipe denominator}"))*100)+"%";

 


Leave a Reply