How to store old value of field 1 and new value of field 1 in the string field in catalog form

Rajveer
Tera Expert

Hello Experts,

 

I have field 3 field in catalog form 
Manager 
location 

department 

Whenever above field value changes on catalog form , need to store in string field : updated field .

 

1. if one field value changes only show one field value in updated field .

Ex : Manager changes from abc to XYZ

 

2.if two field value changes only shows two field value in updated field
Ex : Manager changes from abc to XYZ

Department changes abc to XYZ

 

 

 

4 REPLIES 4

ShubhamGarg
Kilo Sage

Hello @Rajveer ,

It would be better to define a onChange Catalog Client Script.

onChange function stores both oldValue and newValue as a parameter.

You can hide/unhide other variables basis on change of one variable value.

 

If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Shubham

I have tried .but it's not working for me

To help you further, Can you please share code snippet?

 

Regards,

Shubham

Manoj R Zete
Tera Expert

To achieve this requirement, you can use a onChange Catalog Client Script in ServiceNow

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

var updatedFields = [];

// Check if Manager field changed
if (g_form.getValue('manager') != oldValue) {
updatedFields.push('Manager');
}

// Check if Location field changed
if (g_form.getValue('location') != oldValue) {
updatedFields.push('Location');
}

// Check if Department field changed
if (g_form.getValue('department') != oldValue) {
updatedFields.push('Department');
}

// Update the 'updated_field' with the changed fields
g_form.setValue('updated_field', updatedFields.join(', '));
}


If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Manoj