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-18-2017 03:16 AM
Hi Rody,
You can have a update BR on the new table condition when u_comment changes.
Script :
var gr = new GlideRecord("incident");
gr.addQuery("number",current.u_number);
gr.query();
if(gr.next()){
gr.comments = current.u_comments;
gr.update();
}
Hope this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 03:21 AM
Hi Rody,
One change in the script. you have mentioned comments field on incident to be updated and priority is not needed so here is the updated script:
var incNumber = current.u_number;
var incRecord = new GlideRecord('incident');
incRecord.addQuery('number',incNumber);
incRecord.query();
if(incRecord.next()){
incRecord.comments = current.u_short_description;
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 03:39 AM
Hi Ankur,
If i add:
incRecord.short_description = current.u_short_descripton;
It will update the short description of that incident.
But for the comments fields on incident, it seems not to work. Is the comments fields special in any way?
incRecord.comments = current.u_short_description; //u_short_description is a normal string field
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 03:45 AM
Hi Rody,
Comments can be seen in Activity section. Its journal entry field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 03:47 AM
Hi Rody,
Yes it is different since it is a journal field. use below and it should work
var incNumber = current.u_number;
var incRecord = new GlideRecord('incident');
incRecord.addQuery('number',incNumber);
incRecord.query();
if(incRecord.next()){
var fieldName = 'comments';
incRecord[fieldName].setJournalEntry(current.u_short_description);
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