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

snehabinani26
Tera Guru

Hi rody,




Create an after update Business Rule saying when Assignment group changes to Cab on Incident table



In Script section write the below code.



var gr = new GlideRecord("u_new_table");


gr.initialize();


gr.u_short_description = current.short_description;


gr.u_priority = current.priority;


gr.insert();



Hope this helps you


Hello,

 

I've had the same problem, the field 'expected_start' (date time field) from the wm_order table should be copied to the field 'u_scheduled_wot' (string field) on the sn_customerservice_case table which I can't seem to get working with the script.

 

This is what I have currently:

find_real_file.png

Am I doing something wrong ? 

 

 

Thanks

 

 

Karthik Reddy T
Kilo Sage

Hello Rody,



You can write on after businerss rule on Incident table.



BR condition : table is CAB,



Please refer the below sample code



var prob = new GlideRecord("u_new_table");


prob.short_description = current.short_description;


prob.cmdb_ci = current.cmdb_ci;


prob.priority = current.priority;


prob.company = current.company;


prob.sys_domain = current.sys_domain;


var sysID = prob.insert();




current.problem_id = sysID;


var mySysID = current.update();


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

rody-bjerke
Giga Guru

Hi,



Thanks, that helped alot



How would you do it the other way around? Let's say 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.



On the u_new_table I insert the incident number in the field "u_number", together with "u_comments", when I update I want it to update the comments on the incident table where the incident is the same as u_number on the u_new_table.



Best regards,


Hi Rody,



you will have to write after update business rule on "u_new_table" and add condition as u_number field is not empty, query incident table with incident number present in "u_number" field and update shortDescription and priority fields on incident table



var incNumber = current.u_number;


var incRecord = new GlideRecord('incident');


incRecord.addQuery('number',incNumber);


incRecord.query();


if(incRecord.next()){



incRecord.short_description = current.u_short_description;


incRecod.priority = current.u_priority;


incRecord.update();



}



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