Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Action in a Flow when using the data pill returning a decimal number when it should not

Not applicable

Artifacts involved:  Flow and a Action which I built for the flow

The flow is pretty basic so I am not going to spend a bunch of time discussing it here. For the flow you can build a run once trigger on a schedule timer just to have something there.  Then add the Action then add an email step to use the count from the action to populate the body.

 

The Problem: 
I have an Action which I build that takes the sys_id of the user and runs that through a script that get's the count of active tasks in the task table.  When I run test this in the action I am getting the expected number of record count returned. The count is returning the number as a string and is showing the correct results.
When I put this action into the flow and call it, I get the same number returned.  I then want to take the count data pill that it produces and put that into an email in the body.  When I do that it's taking the number and converting it into a decimal number.  Example : Action is returning 71 and Email step in Flow is converting it to 71.0

Question:  How can I get it to return just the number without the decimal point

 

Action Setup:

Inputs: 
Inputs.png

Script Step:

ScriptStep.png

Script: 

(function execute(inputs, outputs) {
//Get user id as input
var userID = inputs.sysid;
//Query for the user tasks
var taskGR = new GlideRecord('task');
taskGR.addQuery('assigned_to', userID);
taskGR.addQuery('active', true);
taskGR.query();
//Set Counter to 0;
var taskCount = 0;
//Loop through records
while (taskGR.next()){
    taskCount++; //add to count
}
//Set output to the count

var taskCountConverted = parseInt(taskCount, 10); // Converts to integer
outputs.count = taskCountConverted;

})(inputs, outputs);

Output Variable

Outputs in Edit Mode.png

 

Outputs: 

 

Outputs.png




Here is what I'm getting returned in the email body:
output in decimal.png

3 REPLIES 3

jcmings
ServiceNow Employee

Sorry, why do you need this line? 

var taskCountConverted = parseInt(taskCount, 10); // Converts to integer

 What happens if you just return taskCount?

Not applicable

Someone suggested converting it to a Int so I tried it.  Actually it doesn't make any difference, I have tried both ways

Animesh Das2
Mega Sage

Hi @Community Alums ,

 

Your count variable is a string as you configured in the Action output.

Can you just try set the taskCountConverted variable as String as shown below,

 

var taskCountConverted = String(taskCount);

 

 

If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das