- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2020 02:28 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2020 02:36 AM
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:
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2020 02:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2020 02:37 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2020 02:39 AM
There are pitfalls in every approach but yes the script include approach is better in terms of reusability.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2020 02:44 AM
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