- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 07:08 PM
Hi all,
We have a requirement whenever user clicks on new change request in related list from RITM for normal , emergency change variables on RITM should get populated in description.
I tried using the script on OOB UI action but no result , Can anyone help with the script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 12:28 AM
Hi,
then use display business rule on change_request and same script
it will work
var ritm = new GlideRecord('sc_req_item');
ritm.get(current.getValue('parent'));
var arr = [];
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value != ''){
arr.push(label + ":" + value + "");
}
}
current.description = arr.join('\n');
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
‎02-09-2022 12:28 AM
Hi,
then use display business rule on change_request and same script
it will work
var ritm = new GlideRecord('sc_req_item');
ritm.get(current.getValue('parent'));
var arr = [];
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value != ''){
arr.push(label + ":" + value + "");
}
}
current.description = arr.join('\n');
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
‎02-09-2022 12:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 12:58 AM
Hi
I have tried with script on display BR , it is working fine. Here it is fetching all variable values but how to fetch it only for particular variables.
Thank you for help.!!
Kind Regards,
Ramya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 01:08 AM
Glad to know that my script worked.
Would you mind marking my response as correct and helpful to close the thread.
The discussion can continue for your further question
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
‎02-09-2022 01:12 AM
For showing particular variable you need to compare the variable name
var ritm = new GlideRecord('sc_req_item');
ritm.get(current.getValue('parent'));
var myVariablesToShow = ['requested_by','email','phone']; // this array holds variables you want to show
var arrayUtil = new global.ArrayUtil();
var arr = [];
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
var name = question.getName();
if(label != '' && value != '' && arrayUtil.contains(myVariablesToShow, name)){
arr.push(label + ":" + value + "");
}
}
current.description = arr.join('\n');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader