How to Use RTTM Variables as condition in Business rule in RITM Table?

HARI KISHAN GVS
Mega Sage

Hi Team,

Can somebody help me on this.

i am trying to copy values from variables(which are in Variable set) to fields in RITM Table by using Business rule.

By using below script in my after business rule which is on the sc_req_item table values are not copied.

(function executeRule(current, previous /*null when async*/) {
// Note: if  i am using if condition like this values are NOT Copied. and if i remove if condition values are copied.

if((current.variables.standard_employee_questions.check_this_box=='true')&&(current.variables.standard_employee_questions.needed_by=='today')){
current.u_requestor = current.variables.standard_employee_questions.requested_for;
current.update();
}}

)(current, previous);

Please let me know how to resolve this? and i can't use run script activity in workflow as my variable set is used in multiple catalog items and they have different workflows. i don't want to modify all the workflows.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

This works fine with a before Insert Business Rule.  When referring to variables in a workflow or BR script, use the syntax current.variables.variable_name, not current.variables.variable_set_name.variable_name, so this script will work.

(function executeRule(current, previous /*null when async*/) {

	if(current.variables.check_this_box.toString() =='true' && current.variables.needed_by == 'today'){
		current.u_requestor = current.variables.requested_for;
	}

})(current, previous);

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

yes you can use workflow run script if you already have catalog item workflow

script would be like this

if(current.variables.standard_employee_questions.check_this_box.toString() =='true' && current.variables.standard_employee_questions.needed_by == 'today'){
	current.u_requestor = current.variables.standard_employee_questions.requested_for;
}

OR

you can also use before insert BR on sc_req_item table with proper condition so that it runs only for your catalog item's RITM

(function executeRule(current, previous /*null when async*/) {

	if(current.variables.standard_employee_questions.check_this_box.toString() =='true' && current.variables.standard_employee_questions.needed_by == 'today'){
		current.u_requestor = current.variables.standard_employee_questions.requested_for;
	}

})(current, previous);

Regards
Ankur

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

Hi Ankur,

I tried BR way, but it's not working as expected. please see the attached screenshots below. 

 

@HARI KISHAN GVS 

then make that BR as After Insert and update as this

(function executeRule(current, previous /*null when async*/) {

    if(current.variables.standard_employee_questions.check_this_box.toString() =='true' && current.variables.standard_employee_questions.needed_by == 'today'){
        current.u_requestor = current.variables.standard_employee_questions.requested_for;
        current.setWorkflow(false);
        current.update();
    }

})(current, previous);

Regards
Ankur

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

Hi,

the actual syntax for accessing any variable be it within variable set or outside variable set is the same

current.variables.variableName

So try this once as mentioned by Brad in before insert BR and it should work fine

(function executeRule(current, previous /*null when async*/) {

    if(current.variables.check_this_box.toString() =='true' && current.variables.needed_by.toString() == 'today'){
        current.u_requestor = current.variables.standard_employee_questions.requested_for;
    }

})(current, previous);

Regards
Ankur

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