Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Creating FIX Script which can be re-used for different values

HT
Tera Contributor

Hi, 

i have created a fix script to modify fields in the Incident table. 

In some cases we need to add values after creation. 

Managed to create the fix script, but the values i need to supply to the Incident table contain a different INC id everytime i run the script. 
Is there a way to make the script 're-usable' ... that is... Current when i use a new ID to search for and supply the values, i need to save the FIX Script, which results in a new version .. We will end up with a lot of versions this way. 

Fix script looks like this: 

(number and u_external_relation_id will both have different values everytime i need to run the script) 

 

updateIncident();

function updateIncident(){
try{
gs.info('Fix Script started for updateIncidentID');
var inc = new GlideRecord('incident');
inc.addQuery('number=INC0014924');

//inc.setLimit(10);
inc.query();
if(inc.next()){

inc.u_external_relation_id = 'INM000000452354';

inc.setWorkflow(false); 
inc.update();
}
gs.info('Fix Script Ended for updateIncidentID');

}
catch(ex){
gs.info('Exception is: ' + ex);
}
}

 

 

Thanks 

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee

Hi,

You could easily just have it as a function in a script include and call it from scripts - Background. Script include could look something like this:

 

find_real_file.png

And then in the scripts - Background you just call it like this:

 

new incUtils().updateExtRel('INC0014924','INM000000452354')

//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor’s Guide To ServiceNow

View solution in original post

8 REPLIES 8

I did not know this and as I have some junior developers on the team whom I've seen do this for various use cases I am happy to know this now! Thank you Goran!

It's inspiring to see that things like this still hold true. 😀

Goran WitchDoc
ServiceNow Employee

Hi,

You could easily just have it as a function in a script include and call it from scripts - Background. Script include could look something like this:

 

find_real_file.png

And then in the scripts - Background you just call it like this:

 

new incUtils().updateExtRel('INC0014924','INM000000452354')

//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor’s Guide To ServiceNow

HT
Tera Contributor

Great, 

didn't think about using a function for this. 

Thanks!