Call script include from a schedule job and then trigger notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2023 11:59 PM
Hi All,
I have a requirement, where i have created a script include and i need to call this script include in a schedule job which runs periodically and when script include returns true i need to trigger notification i.e call a event in schedule job.
Below is the Script include
Script include name - CriteriaforUser
Test1 : function(usersysid){
var Date1 ='';
var encqry='some query';
var grUserRec = new GlideRecord('sys_user');
grUserRec.addQuery('sys_id',usersysid);
grUserRec.addEncodedQuery(encqry);
grUserRec.query();
if(grUserRec.next()){
Date1 = grUserRec.date;
var gdt2 = new GlideDateTime();
var gdt = new GlideDateTime(Date1);
var strtdate = gdt.getDate();
var dgt = new GlideDateTime();
var nowdt = dgt.getDate();
var duration = gs.dateDiff(nowdt, strtdate, true);
if(duration>0)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
},
I need to call this script in a schedule job and need to trigger the event once the script include returns true.
Can someone help me with the schedule job as i am not understaing the way to call it.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 12:13 AM
Hi @Nikki18 ,
Could you please elaborate what you are trying to achieve with this script include?
Thanks,
Gopi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 03:07 AM
Hi Gopi,
the requirement is i need to get particular set of users who belong to certain cmpanies and certain roles then trigger the email only to those users.
So i have added my query in the script include and call this script include in schedule job, and call the event only when script include returns true, so that only those users will receive email.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 12:14 AM
Hi @Nikki18 ,
Hope you are doing good.
You can call this script include in the schedule job by using below code.
new CriteriaforUser().Test1(user's sys_id)
I guess you need to run the same for multiple records so you can do the same in a while loop
var getUser = new GlideRecord("sys_user");
getUser.addQuery(Add your query here);
getUser.query();
while(getUser.next()){
if(new CriteriaforUser().Test1(getUser.sys_id)){
gs.eventQueue(Add your event here)
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 01:05 AM
Hi Aditya,
Thank you for the reply,
i have already added the query for user record in the script include.
the requirement is i need to get particular set of users who belong to certain cmpanies and certain roles then trigger the email only to those users.
This is what contains in the encoded query in script include.
Hope the script include is right. Can you please check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 12:37 AM
Hi,
Please find the syntax to call script Include
var notify = new CriteriaforUser.Test1
And in the script include8 include gs.eventQueue as per your logic
Script include name - CriteriaforUser
Test1 : function(usersysid){
var Date1 ='';
var encqry='some query';
var grUserRec = new GlideRecord('sys_user');
grUserRec.addQuery('sys_id',usersysid);
grUserRec.addEncodedQuery(encqry);
grUserRec.query();
if(grUserRec.next()){
Date1 = grUserRec.date;
var gdt2 = new GlideDateTime();
var gdt = new GlideDateTime(Date1);
var strtdate = gdt.getDate();
var dgt = new GlideDateTime();
var nowdt = dgt.getDate();
var duration = gs.dateDiff(nowdt, strtdate, true);
if(duration>0){
gs.eventQueue(event,gr,param1,param2);
}