
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2020 07:22 AM
Hello,
I have an order guide/catalog item that uses a variable set and the variables are cascaded. If someone changes a variable on an associated task I want to capture the change in the activity stream work note. How can I accomplish this?
Thanks,
Joe
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2020 01:04 PM
Can you test this once
var key;
for(key in current.variables){
if(current.variables[key] != previous.variables[key]){
current.work_notes = "Variable changed "+key + "Value Changed to"+current.variables[key];
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2020 08:23 PM
If you want this to run for all catalog items then just use this condition in BR
current.variables.changes()
For determining which variable changed use what mentioned by Pranav
Just to add on it you can print the previous value of variable as well
This will print all the variables which got changed with their previous value combined and then put in work notes
var str = '';
var key;
for(key in current.variables){
if(current.variables[key] != previous.variables[key]){
str = str + 'Variable Changed ' + key + ' from ' + previous.variables[key] + ' to ' + current.variables[key] + '\n';
}
}
current.work_notes = str;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 09:10 AM
Thank you, Ankur! This is helpful.
This now prints the variable, previous value and new value. It is also printing all of the variables which is not needed. Is there a way to modify the script to avoid printing all of the variables?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 09:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 10:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 11:52 AM
var key;
for(key in current.variables){
if(current.variables[key] != previous.variables[key]){
current.work_notes = "Variable changed "+key + "Value Changed to"+current.variables[key];
}
}