Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Development of Fix Script to change incidents

lucasjt
Tera Contributor

Hey guys!

 

I need a Fix Script to change the name of the Channel field (contact_type) for 365 incidents:

lucasjt_1-1702328183826.png

Basically I need to replace "ChatBot" with "Chatbot".

lucasjt_2-1702328407649.pnglucasjt_3-1702328424677.png

 

Thanks!

 

3 REPLIES 3

Stefan Georgiev
Tera Guru

Hello @lucasjt ,

you can you this code:

var incidentGR = new GlideRecord('incident')
incidentGR.addQuery('contact_type', 'ChatBot') // check if this query returns the 365 records or build the right query to get only the records you want to update

incidentGR.query()

while(incidentGR.next()){

incidentGR.contact_type = "Chatbot";
incidentGR.update()
}

jonsan09
Giga Sage
Giga Sage

You can try the below:

 

var updateINC = new GlideRecord('incident');
updateINC.addEncodedQuery('contact_type=INSERT BAD CONTACT TYPE');
//updateINC.setLimit(); //Use to limit number of records to update at a time, if a large number of reocrds are to be updated then there might be a performance impact.
updateINC.query();
while (updateINC.next()) {
    updateINC.contact_type = 'GOOD CONTACT TYPE';
    //Prevent BRs/Flows/Workflows from Triggering
    updateINC.setWorkflow(false);
    //Prevent updated by and updated fields from changing
    updateINC.autoSysFields(false);
    updateINC.update();

}

 

Hi @LucasJ  using batch update instead of a while loop would be more efficient. Update mutiple will update all records just like the while loop. You should still set  workflow and sysfields to false.

 

see --

https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/g...

 

Hope that helped

--

Bala