How can we put First Character as Dollar Sign on Catalog Item variable field?

VIKASM535239375
Kilo Sage

How can we put First Character as Dollar Sign on Catalog Item variable field?

4 REPLIES 4

Ct111
Giga Sage

Hello ,

 

you can use below regular expression on the variable 

 

^\$

 

and do setting for your regualr expression on variable like below 

 

LINK

 

In this way you will achieve your requirement without scripting, rest is your choice as there are mulitple ways of doing a thing.

 

I hope this information helps.

Community Alums
Not applicable

Hi

we try to achieve this requirement by adding on-change client script with following code in it.

you just do edit and put you variable name in SetValue method.

polnilesh99_0-1738324444747.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@VIKASM535239375 

set the default value as $ in the variable configuration and the users can type in the value there

OR

you can use onChange catalog client script and let user type and then add the prefix, ensure it doesn't get into loop

Something like this

function onChange(control, oldValue, newValue, isLoading) {
    if (!isLoading || newValue == '') {
        return;
    }

    if (!newValue.startsWith('$')) {
        g_form.setValue('variableName', '$' + newValue);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@VIKASM535239375 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader