Example of copying field values from one table to another
This content was last updated in 2023. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 04:10 AM
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,
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 04:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2021 07:27 AM
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:
Am I doing something wrong ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 04:16 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 03:08 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 03:13 AM
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