Conditional Scheduled imports
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 05:25 AM
Hello,,
I'm working on Scheduled imports and I want to execute the scheduled import based on condition, can some one share the sample script to evaluate true or false(below image), I want to write a
Script like below (Example condition like for all P1 incidents this scheduled import will be execute), Can I do like this? please share your ideas.
var gr = new GlideRecord('incident');
gr.addQuery('priority',1);
gr.query();
while(gr.next()){
answer = true;
}
Regards,
Ganesh.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 05:32 AM
Genesh,
Here is an example script for condition.
//Return 'true' to run the job
var answer = false;
//Get the day of month.
var now = new GlideDateTime();
//Run only on 2nd of month
if(now.getDayOfMonthLocalTime() == 2){
answer = true;
}
answer;
The condition is not going to have access to the data your importing since it hasn't been imported if that's what you're trying to do with your example.
From Docs.
| Condition | Write the script to be used to evaluate whether an import should run. This field is visible if you selected the Conditional check box. |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 05:39 AM
Thanks for response Patrick. That sample will help me.
Can I do this like below.
var ga = ' ';
var gr = new GlideRecord('incident');
gr.addQuery('priority',1);
gr.query();
while(gr.next()){
ga = 'move';
}
if(ga=='move'){
answer = true;
}else{
answer = false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 05:47 AM
If you do a GlideRecord query and a while loop, you could be there a while as your list of records grows. You really only want to know if there 1 record that matches the condition.
Something like this might be more efficient than getting ALL incidents, you really only need 1.
(function () {
var inc = new GlideRecord('incident');
inc.setLimit(1);
inc.addQuery('priority', 1);
inc.query();
if (inc.next()) {
return true;
}
return false;
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 05:51 AM
It might need to be answer vs return.
