Example of copying field values from one table to another

rody-bjerke
Giga Guru

Hi,

Could anyone give an example of the following:

I have 2 tables: Incident and u_new_table.

On the Incident table i have short_description, priority

On the u_new_table i have u_short_description and u_priority.

Then when an incident is created and assignment_group is "CAB", I want a business rule to create a new ticket in the u_new_table with the data in the fields short_description and priority.

Let's say Incident have short_description = "New ticket" and priority = "High", the assignment_group is set to CAB. Then the information is moved on submit/update to the form u_new_table and populate the fields u_short_description and u_priority.

How would that be done using best practice.

Best regards,

16 REPLIES 16

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Rody,



Have an after insert business rule on incident table and add condition as assignment group is "CAB"



Fetch the required values such as short description and priority. you need to ensure that drop down choice values are same in both the tables for incident and u_new_table field for Priority field.



Business rule script:


var gr = new GlideRecord('u_new_table');


gr.initialize();


gr.u_short_description = current.short_description;


gr.u_priority = current.priority;


gr.insert();



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Hi there - i've been trying a nearly-identical script to this in a BR, but it always puts in a second, empty row in the receiving second table (in the above example, that would be 'u_new_table') - how can I avoid that happening?   Otherwise, the data copies across from first table to second with no problem?



kevin


Hi,

I have a similar need. When creating a manual sc_task from a requested item (sc_req_item), I want the Business Service from sc_req_item copied to the same field on the newly made sc_task.

I have made this after insert BR on sc_req_item table but it doesn't work:

var gr = new GlideRecord('sc_task');
gr.initialize();
gr.business_service = current.business_service;
gr.insert();

The Business Services field is a reference field from the task table. Is that the reason to why it doesn't work?

Best regards
Thomas

I have tried this (see attachment) but nothing is populating in the second table field.  I only did 1 field to test this and had no errors in the script.

 

???