How to write UI action script to bring RITM variables to change request description?

Dakarapu Ramya1
Kilo Contributor

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.

find_real_file.png

I tried using the script on OOB UI action but no result , Can anyone help with the script:

find_real_file.png

1 ACCEPTED SOLUTION

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

19 REPLIES 19

shloke04
Kilo Patron

Hi @Dakarapu Ramya ,

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);

find_real_file.png

Result:

This is working for me in my PDI when CHange Request is created from RITM Related List

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi @shloke04 

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.

Hi,

Just change the Operation of BR from Before to Display and that will resolve your issue as shown below:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Ankur Bawiskar
Tera Patron
Tera Patron

@Dakarapu Ramya 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 

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