Auto Increment Numerical Value in Catalog Item Variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2021 10:28 PM
Hello Everyone.
I'm having the following requirement on Catalog Item Variable Form. There is a Variable named as Serial Number. Every time a catalog item is requested, the field needs to be auto-populated.
We have to populate the variable with the following information - ('First letter of first name of Requestor' + ' Last letter of first name Requestor' + 10500).
The number is starting with 10500 and every time the Catalog item is submitted the number is auto incrementing and is unique (should not be repeated).
Eg - Requestor Name is JACK. So the serial number would would be JK105001. Next time the catalog item is requested the serial number should be **105002,**105003 and so on.
NOTE - The Variable 'Serial Number' is not mapped to any field on RITM. IS it possible to query variables for a catalog item in SN ?
Please suggest the best way to do this. Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2021 11:48 AM
function onSubmit() {
var ga = new GlideAjax('SerialNumberUtils');
ga.addParam('sysparm_name', 'getExistingSerialNumber');
ga.addParam('sysparm_user_name', g_user.userID);
ga.getXML(getResponse);
}
function getResponse(response) {
var firstName = g_form.getValue('first_name');
var lastName = g_form.getValue('last_name');
var firstChar = firstName.charAt(0);
var lastChar = lastName.charAt(0);
var serialNumber = response.responseXML.documentElement.getAttribute("answer");
if (serialNumber == '') {
serialNumber = firstChar + lastChar + '10500';
} else {
var increment = parseInt(serialNumber.toString().charAt(serialNumber.length - 1)) + 1;
serialNumber = serialNumber.substr(0, answer.length - 1) + increment;
}
//alert('finally we get - ' + serialNumber);
g_form.setValue('serial_number', serialNumber);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2021 10:20 AM
It has to be an OnLoad client script...
Check my script again 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2021 12:44 PM
Hello,
Refer blog
Regards,
Vaishnavi