Copy value field from one table to another table in Business Rule

Diorella Angulo
Tera Expert

Hi,

I couldn't fine a solution for my requirement. I'm learning scripting.

I want to copy a value from Request [sc_request] table to Catalog Task [sc_task] table. It should happen when the field in the Request table is either updated or inserted.

I have the following in the When to run tab.

find_real_file.png

 

This is the script and obviously there is something wrong. I think it is in the gr.addQuery line? Can someone help me with that?

var a = current.work_start;

var gr = new GlideRecord('sc_task')

gr.addQuery('request',current.request)

gr.query();

gr.u_quote_approval_date = a;
gr.update();

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the BR should be after update on sc_request

Ensure you give correct condition so that the BR triggers

Update script as this

I hope work_start and u_quote_approval_date fields are of same type

var a = current.work_start;
var gr = new GlideRecord('sc_task');
gr.addQuery('request',current.getUniqueValue());
gr.query();
while(gr.next()){
	gr.u_quote_approval_date = a;
	gr.update();
}

Regards
Ankur

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

View solution in original post

5 REPLIES 5

current.getUniqueValue() will give the REQ sys_id which will help you to query the sc_task table

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