
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 08:22 AM
For some reason, google searching isn't coming up with any results...
How to call a Fix Script from a scheduled job.
I'm sure it's easy but something I've yet to do and would like someone to post an example. Thanks!
(and please, if your reply is "you can do all the code right in your scheduled job and don't need a fix script"... no need to reply as I have a very specific reason this needs to be done this way 😛 )
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 10:12 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 09:36 AM
Follow below steps.
1. Create scheduled job with required name. Suppose: YorFixScriptName
2. Create fix script with below code & once saved copy sys_id of record.
var job = new GlideRecord('sysauto_script');
job.get('name', 'YourFixScriptName');
SncTriggerSynchronizer.executeNow(job);
3. Create an entry in sys_update table with format as below.
sys_fix_script_sysidoffixscript.xml something like
sys_fix_script_9aed87713b41030060a8695593efc483.xml
4. Scheduled job created in Step 1 needs to have below code.
var gr = new GlideRecord('sys_update');
gr.addQuery('name', 'NamefromStep3');
gr.query();
var ab=gr.next();
if(ab)
{
var abc=new canclritm();//canclritm suppose is script include name that holds actual logic
abc.run(); //abc being function name
}
5. Script include to hold actual logic. For instance for above canclritm without Client Callable being checked.
var canclritm = Class.create();
canclritm.prototype = {
initialize: function() {},
run: function() {
var canclritm = new GlideRecord('sc_req_item');
//Replace below with query required by right clicking the last parameter from query & then copying
canclritm.addQuery('number=RITM0112469');
canclritm.query();
while (canclritm.next()) {
canclritm.state = '4';
canclritm.stage = 'Request Cancelled';
var salu = 'Dear ' + canclritm.request.requested_for.getDisplayValue() + ',';
var body = 'Your ' + canclritm.cat_item.getDisplayValue() + ' was not submitted correctly. Please raise the request against a relevant service again if it is still needed.';
//gs.print(salu+'\n\n'+body);
canclritm.comments = salu + '\n\n' + body;
canclritm.update();
}
},
type: 'canclritm'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 10:16 AM
Thank you for your reply.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 10:12 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 10:23 AM
Hi
You can schedule both conditional and non-conditional scripts.
Procedure
- Navigate to System Definition > Scheduled Jobs.
- Click New.
- Select Automatically run a script of your choosing.
- On the form, fill in the fields.
Example:
The following is an example of a conditional script. This example runs the scheduled job only if there are active incidents older than 30 days.
// Only run this Scheduled Job if there are active Incidents over 30 days old var ga = new GlideAggregate('incident'); ga.addAggregate('COUNT'); ga.addQuery('active', 'true'); ga.addQuery('sys_created_on', '<', gs.daysAgo(30)); ga.query(); ga.next(); ga.getAggregate('COUNT') !== '0'
refer the following thread for more.
If it help mark helpful or correct
Thanks and regards
Anil