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
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

Kalaiarasan Pus
Giga Sage

You can create a system property and use it in your fix script. This way you would just need to update the property everytime before running the fix script.

Just remember updating a system property will flush the whole cache each time you update it 😃

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

There are pitfalls in every approach but yes the script include approach is better in terms of reusability.

absolutely, just wanted to mention it since many people don't know about the cache flush when you change values 🙂

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