Copy filed values from Child incident to parent incident

Souvick6917
Tera Contributor

Hi team,

The subject line is bit confusing but the required functionality is that only. We have incidents and an UI action called 'Approve Major Incident' to create a major incident with that respective incident. Then, the initial incident becomes child and the new major incident is the parent. We have a parent field on the child incident showing the incident id . Requirement is to copy the field values of child incident(initial incident) to the newly created major incident(parent).

There is a mixture of reference and text fields. I need help on script of the business rule for this requirement.

 

Thanks in Advance

Souvick

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Souvick6917 Instead of creating a business rule, you can simply utilise the Approve Major Incident UI Action where you are creating a major incident, set the values from the current record on the new major incident record you are creating.

 

Your UI Action script could like like the following.

 

var majorIncident = new GlideRecord('incident');
majorIncident.initalize();
majorIncident.short_description = current.short_description+'';
majorIncident.description = current.description+''; //similarly set the other fields.
current.parent = majorIncident.insert(); //insert the major incident here
current.update();

 

Hope this helps.

The issue here is the UI action is in a different scope and we dont want to modify the code as it has been used in number of other places. I want to achieve this part as after business rule. Can you help me on the coding as my code is working.

 

 

function executeRule(current, previous /*null when async*/) {
//Get parent Incident
var inc = new GlideRecord('axepta_incident');
inc.addQuery('number',current.sys_id);
inc.query();
gs.addInfoMessage("current incident = " + current.sys_id); //for testing
while (inc.next()){
    var child =  inc.number;
    var gr = new GlideRecord("axepta_incident");
    gr.addQuery("number", child);
    gr.query();
    gs.addInfoMessage("child incident = " + inc.parent);
    if (gr.next()) {
       
    }
   
    // Setting values of Incident on parent incident
    inc.setValue('contact_type',current.contact_type);
    inc.setValue('account',current.account);
    inc.setValue('contact',current.contact);
    inc.setValue('u_payment_channel',current.u_payment_channel);
    inc.setValue('u_means_of_payment',current.u_means_of_payment);
gs.addInfoMessage("current number = " + current.number);
    inc.update();
}



})(current, previous);