business rule Script not return value

sarahjane19
Tera Contributor

Good Morning 

 

I have a scripted business rule that i believe should run when a RITM with a Specific Short description is created/ updated and it should pull a variable for Start Date ( start_date) in to a field on the RITM Form.  however it isn't working 

can anyone help?  This is the Script 

 

(function executeRule(current, previous /*null when async*/) {
 
// Get the RITM sys_id
var ritmID = current.sys_id;
 
// Search sc_item_option_mtom for variables on this RITM
var varMtom = new GlideRecord('sc_item_option_mtom');
varMtom.addQuery('request_item', ritmID);
varMtom.query();
 
while (varMtom.next()) {
var itemOption = varMtom.sc_item_option.getRefRecord();
if (itemOption.name == 'start_date') {
current.u_glide_date_1 = itemOption.value;
break; // stop once we find the right variable
}
}
 
})(current, previous);
 
 
Thanks 
1 ACCEPTED SOLUTION

Aranya
Tera Guru

Hi @sarahjane19,
You can just use "current.variables.start_date". 
current.variables.<variable_name> will usually fetch the variable value from the RITM form.

Just use:
current.<field_name> = current.variables.<variable_name>
This will set the value of the variable which is Start Date here to the RITM field.

Please mark as Helpful and if this worked for you kindly mark this reply as the Solution!

View solution in original post

3 REPLIES 3

Aranya
Tera Guru

Hi @sarahjane19,
You can just use "current.variables.start_date". 
current.variables.<variable_name> will usually fetch the variable value from the RITM form.

Just use:
current.<field_name> = current.variables.<variable_name>
This will set the value of the variable which is Start Date here to the RITM field.

Please mark as Helpful and if this worked for you kindly mark this reply as the Solution!

J Siva
Tera Sage

Hi @sarahjane19 

You can access all the varaibles from the RITM/SC TASKS using the below format.

 

current.variables.<catalog variable name>

 

For your scenario, it would look something like this

current.variables.start_date

Regards,
Siva

Ankur Bawiskar
Tera Patron
Tera Patron

@sarahjane19 

you can use this logic to access the variable value and set in the RITM field

// give the field name and date variable name
current.setValue('dateField', current.variables.dateVariableName);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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