We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Not applicable

Hi, 

You can do this to set when to run:

find_real_file.png


The table sc_request extends sc_task then you're working with fields of the same table. 

Since you're working on the same record, your script can be as simple as this:

find_real_file.png


Please mark my response as Correct or Helpful, if you find it appropriate. 

________________________

Carlos Camacho
https://www.linkedin.com/in/camachojunior

 

Hi,

It did not work. Any ideas? 

find_real_file.png

 

find_real_file.png

Ankur Bawiskar
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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank Ankur. I tried your script and worked fine. 

Yes, both fields are the same. 

What does the getUniqueValue(); do? Does it get the request number?

 

Here is the solution:

find_real_file.png

find_real_file.png