To check if user has changed a variable value in form via onChange script in portal

ANGELIN TOM
Tera Contributor

Hi

Is there a way to know if the user has changed a field value in a catalog item.

I am using onChange catalog client script. On change of a variable in portal i need to know if the field was changed by user. For the context I am using API to autopopulate the same field but the field is still editable so the user can change the value. So i need to know when its modified by user. I have tried g_form.isUserModified function but it didn't work.

3 REPLIES 3

johnfeist
Mega Sage
Mega Sage

Hi Angelin,

Since you are using a Catalog Client Script, all you need to do is have your script trigger OnChange for the variable in question.  From there, just compare the values in the newValue and oldValue variables that are created when the function fires.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Alok Gupta5
Tera Guru
Tera Guru

Hello,

You can use the updated by and gs.getUserId(); and check if both are same then it will work.

you have to use UI policy script.

Regards,
Alok Gupta

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

oldValue and newValue should help you; but that would require onChange client script on each variable

You can use hidden text variable and populate in it the values which you are auto-populating in all the variables.

then in onSubmit you can compare the values against each variable against the value present in the hidden text variable

That would tell you which variables got changed as part of user input

Regards
Ankur

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