- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hi @Ankur Bawiskar,
I saw your earlier response in the community about updating work notes. I tried that method, and it successfully updates a single variable. However, I need to update multiple variables at once. For example, if there are 10 to 15 variables, what should I do? Could you explain how to achieve this?
Below is the code I’m using to update a single variable with the OnChange (Catalog Client Script):
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
so what debugging did you do?
share your BR screenshot and latest script.
also small thing you will have to update is check the previous and current value, if different then only add that in array
I updated the script with gs.info(), use that and share the analysis
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var arr = [];
var variableArr = ['variable1', 'variable2', 'variable3'];
for (var i = 0; i < variableArr.length; i++) {
if (previous.variables[variableArr[i]] != current.variables[variableArr[i]]) {
gs.info('value changed for variable' + variableArr[i]);
arr.push('Variable changed from ' + previous.variables[variableArr[i]] + ' to ' + current.variables[variableArr[i]]);
}
}
current.work_notes = arr.join('\n');
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Glad to know that my script is working fine.
To get Display value update as this.
-> use getDisplayValue()
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var arr = [];
var variableArr = ['test', 'software_title', 'requested_for'];
for (var i = 0; i < variableArr.length; i++) {
if (previous.variables[variableArr[i]] != current.variables[variableArr[i]]) {
arr.push('Variable changed from ' + previous.variables[variableArr[i]].getDisplayValue() + ' to ' + current.variables[variableArr[i]].getDisplayValue());
}
}
current.work_notes = arr.join('\n');
})(current, previous);
I believe I have answered your question and you can enhance it further.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Ankur Bawiskar ,
I hope you’re doing well. I tried this solution, but it didn’t work for me. Is there another way to implement this method?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
so what debugging did you do?
share your BR screenshot and latest script.
also small thing you will have to update is check the previous and current value, if different then only add that in array
I updated the script with gs.info(), use that and share the analysis
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var arr = [];
var variableArr = ['variable1', 'variable2', 'variable3'];
for (var i = 0; i < variableArr.length; i++) {
if (previous.variables[variableArr[i]] != current.variables[variableArr[i]]) {
gs.info('value changed for variable' + variableArr[i]);
arr.push('Variable changed from ' + previous.variables[variableArr[i]] + ' to ' + current.variables[variableArr[i]]);
}
}
current.work_notes = arr.join('\n');
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Ankur Bawiskar,
I tried this as well, but it's still not working. I've shared the screenshot for your reference.
Business Rules: Before update condition work notes changes
Previous Variable value:
New variable updated:
It appears that no values are being updated in the work notes.
Thanks,
Abbas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
your BR is before update? what's the trigger condition? share screenshots
Are you sure your BR is running fine?
add these logs and share what came in LOG
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var arr = [];
var variableArr = ['test', 'software_title', 'requested_for'];
for (var i = 0; i < variableArr.length; i++) {
gs.info('previous value for variable ' + variableArr[i] + ' is ' + previous.variables[variableArr[i]]);
gs.info('current value for variable ' + variableArr[i] + ' is ' + current.variables[variableArr[i]]);
if (previous.variables[variableArr[i]] != current.variables[variableArr[i]]) {
gs.info('value changed for variable' + variableArr[i]);
arr.push('Variable changed from ' + previous.variables[variableArr[i]] + ' to ' + current.variables[variableArr[i]]);
}
}
current.work_notes = arr.join('\n');
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Ankur Bawiskar,
I noticed the issue and, for testing purposes, I temporarily added the condition for Business Rules. I have now removed that condition and tried the code again. It's working fine, but it's returning the sys_id instead of the values I need.
Business Rule Script:
Work Notes: