- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 02:12 PM
Hi all,
I need help with a script that's been bugging me. I am working on a service portal catalog item that assigns a number that is incrementally generated for each successful submission. The number field is read-only and viewable only on TASKs that are generated from the RITM. The problem I'm having is that on incrementing a previous value and assigning it back to the variable, the number I know should be an integer is actually getting saved as a floating point number.
Expected Result:
grp_seq = 15; line_nbr = 15
Actual Result:
grp_seq = 15.0; line_nbr = 15.0
var number;
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('someQuery');
gr.query();
if (gr.next()) {
number = parseInt(gr.variables.grp_seq.toString());
if (number == "") {
/*Initialize the sequence if first submission*/
current.variables.grp_seq = 1;
current.variables.line_nbr = 1;
}
else {
/*Increment for each successful submission*/
var newNum = parseInt(number) + 1;
current.variables.grp_seq = newNum;
current.variables.line_nbr = current.variables.grp_seq;
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 02:57 PM
Try adding toString() to the setting of the variables:
current.variables.grp_seq = newNum.toString();
current.variables.line_nbr = current.variables.grp_seq.toString();
That worked for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 02:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 02:57 PM
Try adding toString() to the setting of the variables:
current.variables.grp_seq = newNum.toString();
current.variables.line_nbr = current.variables.grp_seq.toString();
That worked for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2020 05:50 AM
Awesome. That worked. Thanks for the help.