- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 12:40 AM
Hi All,
I was working on a small requirement where i need to capture the count and then do the increment by 1 whenever ticket is updated by caller or assignee, below code is written and working but i want to
Covert countOfComReq, countOfComAgent variables to number using Number() before incrementing it.
If (countOfComReq ) {
countOfComReq = Number(countOfComReq );
} else {
countOfComReq = 0;
}
countOfComReq++;
Note: countOfComReq and u_communication_count_by_assignee both fields are string type.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 05:41 AM
We can use Number() in ServiceNow Scripting. For reference check the below link
if (gs.getUserID() == current.caller) {
var countOfComReq = current.getValue('u_communication_count');
countOfComReq = Number(countOfComReq); // Convert to a number
countOfComReq++;
current.setValue('u_communication_count', countOfComReq.toString());
}
if (gs.getUserID() == current.assigned_to) {
var countOfComAssignee = current.getValue('u_communication_count_by_assignee');
countOfComAssignee = Number(countOfComAssignee); // Convert to a number
countOfComAssignee++;
current.setValue('u_communication_count_by_assignee', countOfComAssignee.toString());
}
Mark the comment as a correct answer and also helpful if this has helped to solve the problem.
Krishna Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 05:28 AM
I don't know that Number() is a valid JavaScript method. Use parseInt() instead.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 05:41 AM
We can use Number() in ServiceNow Scripting. For reference check the below link
if (gs.getUserID() == current.caller) {
var countOfComReq = current.getValue('u_communication_count');
countOfComReq = Number(countOfComReq); // Convert to a number
countOfComReq++;
current.setValue('u_communication_count', countOfComReq.toString());
}
if (gs.getUserID() == current.assigned_to) {
var countOfComAssignee = current.getValue('u_communication_count_by_assignee');
countOfComAssignee = Number(countOfComAssignee); // Convert to a number
countOfComAssignee++;
current.setValue('u_communication_count_by_assignee', countOfComAssignee.toString());
}
Mark the comment as a correct answer and also helpful if this has helped to solve the problem.
Krishna Sharma