- 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
08-05-2024 06:22 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 10:40 AM
It's inspiring to see that things like this still hold true. 😀
- 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-16-2020 12:39 PM
Great,
didn't think about using a function for this.
Thanks!