Auto number/increment when adding rows to multi-row variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 04:45 PM
I'm trying to auto increment the Line Number field (see screenshot) in a multi-row variable set with no luck. I've tried different scripts but they all seemed to fail to find the existing value of the Line Number to increment to the next number. Has anyone been successful in doing this?
I've tried the code included in the this post: https://www.servicenow.com/community/now-platform-forum/how-to-create-auto-increment-variable-in-ser...
I've tried different variations of the code from the post and this is most recent one I have tried:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
var mrvs = g_form.getValue('line_number');
if (mrvs) { // Check if mrvs is not empty
try {
var json = JSON.parse(mrvs);
for (var i in json) {
json[i].line_number = parseInt(i) + 1; // Convert 'i' to a number and add 1
}
var jsonstring = JSON.stringify(json);
g_form.setValue('line_number', jsonstring);
} catch (error) {
g_form.addErrorMessage('Error parsing JSON: ' + error);
}
} else {
g_form.addErrorMessage('The line number value is empty.');
}
}
}
Any help will be greatly appreciated. Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 10:48 AM
I found the answer to my question in this post:
https://www.servicenow.com/community/itsm-forum/how-to-increase-row-number-automatically-when-we-cli...