The CreatorCon Call for Content is officially open! Get started here.

Auto Increment Numerical Value in Catalog Item Variable.

Aks6
Kilo Contributor

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.

12 REPLIES 12

Aks6
Kilo Contributor
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);

}

It has to be an OnLoad client script...

Check my script again 🙂