How to store old value of field 1 and new value of field 1 in the string field in catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 06:16 AM - edited 08-20-2024 06:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 06:23 AM - edited 08-20-2024 06:23 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 06:43 AM
I have tried .but it's not working for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 07:17 AM
To help you further, Can you please share code snippet?
Regards,
Shubham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 07:43 AM
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