The CreatorCon Call for Content is officially open! Get started here.

Need help to standardize a BEFORE Insert BR which is running in Incident table

Shaji T M
Tera Contributor

Good Day!

As part of Moogsoft integration, we are using one BEFORE Insert BR to avoid duplicate incidents. Need your help to standardize that BR as suggested by ServiceNow.

Here is the details

 

when to run : Before Insert

order : 100,001

Advanced:

 

(function executeRule(current, previous /*null when async*/ ) {

    if (current.operation() == "insert") {
        if (current.x_kpmg3_pit_inc_em_uniquekey != "") {
            var gr = new GlideRecord("incident");
            gr.addQuery('x_kpmg3_pit_inc_em_uniquekey', current.x_kpmg3_pit_inc_em_uniquekey);
            var query = "active=true^stateNOT IN6,7,8";
            gr.addEncodedQuery(query);
            gr.query();
            if (gr.next()) {
                if (current.x_moogs_incident_m_moog_situation_id != "") {
                    gr.work_notes = "Description received from Moogsoft: " + current.description + " /n Situation ID:" + current.x_moogs_incident_m_moog_situation_id;
                    gr.x_moogs_incident_m_moog_situation_id = current.x_moogs_incident_m_moog_situation_id;
                    gs.log("Description received from Moogsoft: " + current.description + " and Situation ID:" + current.x_moogs_incident_m_moog_situation_id);
                }
                    gr.update();
                current.setAbortAction(true);
            }
        }
    }

})(current, previous);
 
Any help on this is highly appreciated.
 
1 REPLY 1

SanjivMeher
Kilo Patron
Kilo Patron

It looks like you are directly trying to write to the incident table from the integration.

Instead, you could have used import Api to put the values to a import table and then mapping the fields with x_kpmg3_pit_inc_em_uniquekey as coalesce. 

 

But if thats not an option, what you have looks fine to me, with till abort action of insertion of an incident, if there is a matching incident.


Please mark this response as correct or helpful if it assisted you with your question.