How to create auto increment variable in service catalog

Srini19
Tera Contributor

Hi,

Use case:

when on change field i need to have the other variables prefixed with text and auto increment number.

Example:

Based on other field change my variable need to prefix with auto number like"TEMPxxxxxx". Please advise how we can achieve this in Service catalog.

Thanks

Srini

1 REPLY 1

Sai Kumar B
Mega Sage
Mega Sage

Hi Author,

The only way to do this is using the OnChange() client script, Could you try the below approach?

1.) First set some default value for your number variable

2.) Write onChange() client script on another variable

function onChange(oldValue, newValue, isLoading, isTemplate) {

if(newValue) { //If another variable is not empty
var number = g_form.getValue('number_variable'); //First fetch the default value from the variable
var incrementNumber = Number(number) + 1; //Number() function is used to convert into number
g_form.setValue('number_variable', incrementNumber) //Set the incremented number

}