- 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-08-2022 11:22 PM
Hi
Create a Before Insert Business Rule on Change Request Table with details below:
BR Details:
Table Name: change_request
Type: Before Insert
Condition: Parent is Not empty AND parent.Task Type is Requested Item AND Type isOne OF Normal and Emergency
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
getRITMVariables();
function getRITMVariables() {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.parent);
gr.query();
if (gr.next()) {
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(gr.sys_id); // requested item sys_id
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '' && JSUtil.notNil(vs.get(i).getDisplayValue())) {
current.description += vs.get(i).getLabel() + ": " + vs.get(i).getDisplayValue() + "\n";
}
}
}
}
})(current, previous);
Result:
This is working for me in my PDI when CHange Request is created from RITM Related List
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-09-2022 12:09 AM
Hi
The above script is working to fetch the variables but it is happening after saving the CR record. But here requirement is to have those details on load of change request form.
Thanks & Regards,
Ramya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-09-2022 12:30 AM
Hi,
Just change the Operation of BR from Before to Display and that will resolve your issue as shown below:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-08-2022 11:36 PM
you can have before insert BR on change_request table
Condition:
current.parent != '' && current.parent.sys_class_name == 'sc_req_item' && ( current.type == 'normal' || current.type == 'emergency')
Script:
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:15 AM
Hi
The above script is working to fetch the variables but it is happening after saving the CR record. But here requirement is to have those details on load of change request form, when we click on new.
Kind Regards,
Ramya