Script help to copy fields and insert record into new table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 06:43 PM
Hi Guys,
I want to copy some field values from one ticket into another ticket. The ticket 2 will be created once I click on a button from ticket 1 and the values from ticket 1 will copy into ticket 2. I am testing a very basic ui action script.
// (1) Copy request fields into a new incident
var gr = new GlideRecord("table2");
gr.initialize();
gr.short_description = current.short_description;
gr.insert();
The issue I am having is. Once I make a change in ticket 1 and save it, ticket 2 will automatically get created without me having to click the ui action in ticket 1. The short description field didn't even copy over.
Why is this happening?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 06:51 PM
Hi @Pat Surtan ,
Hope you are doing good.
Could you please check if there is any BR written which is inserting the record in the table2 ?
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 07:03 PM - edited 03-08-2023 07:45 PM
Hello Harshal,
Yes, there is a business rule I created to copy reference field value from table 2 to reference field value to table 1. I believe this is the reason why it is inserting a ticket into table 2 every time I make a change. See the script below.
(function executeRule(current, previous /*null when async*/) {
var a=current.caller_id.getDisplayValue();
//gs.addInfoMessage(a);
var gr=GlideRecord('table2');
current.caller_id = current.u_requested_for;
//gr.addQuery('number',current.change_request.number);
//gr.query();
//if(gr.next())
//{
// gs.addInfoMessage(gr.requested_by);
// gr.u_customer.setValue(a);
gr.update();
})(current, previous);
What's wrong with this script?