Scheduled job not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 10:06 PM
Hi All,
I have created a scheduled job , what i have to do is to get all the sys_id's from first gr and in when i glide change_request form i want the match which are matching with the sys_id, and also i want other sys_id's that is left in u_normal_template query.
temp=[];
var gr=new GlideRecord("u_normal_template");
gr.addEncodedQuery("active=true^Sys_created_onLast12Months");
gr.query();
while(gr._next()){
gs.info("temp"+temp.push(gr.sys_id));
var chg=new GlideRecord("change_request");
chg.addQuery("u_normal_template", gr.sys_id);
chg.orderByDesc("sys_created_on");
if(chg.next()){
//some operation
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 10:15 PM
Hi @Priya75
Try this code.
temp=[];
var gr = new GlideRecord("u_normal_template");
gr.addEncodedQuery("sys_created_onONLast 12 months@javascript:gs.beginningOfLast12Months()@javascript:gs.endOfLast12Months()^active=true");
gr.query();
while(gr._next()){
temp.push(gr.getUniqueValue())
gs.info("temp" + gr.getUniqueValue());
var chg=new GlideRecord("change_request");
chg.addQuery("u_normal_template", gr.getUniqueValue());
chg.orderByDesc("sys_created_on");
if(chg.next()){
//some operation
}
}
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 10:32 PM - edited 08-31-2023 10:33 PM
Hey @Priya75 :
Are you requesting a script to find all normal templates with a change requests which were created in the last 12 months if so you can the below script?
checknormalchnageTempRec();
function checknormalchnageTempRec() {
try {
var allNormaltemp = [];
var chgfoundNomraltemp = [];
var gr = new GlideRecord("u_normal_template");
gr.addEncodedQuery("active=true^sys_created_onONLast 12 months@javascript:gs.beginningOfLast12Months()@javascript:gs.endOfLast12Months()");
gr.query();
while (gr._next()) {
allNormaltemp.push(gr.sys_id.toString());
}
for (var temps in allNormaltemp) {
var chg = new GlideRecord("change_request");
chg.addQuery("u_normal_template", allNormaltemp[temps]);
chg.orderByDesc("sys_created_on");
if (chg.next()) {
chgfoundNomraltemp.push(allNormaltemp[temps].toString());
//Any operation
}
}
gs.info('All Nomral Change templates: '+allNormaltemp);
gs.info('All Nomarl Change templates with change req:'+chgfoundNomraltemp);
} catch (e) {
gs.info("Error in Script: " + e);
}
Mark this as Helpful / Accept the Solution if this clears your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 10:42 PM
how to segregate the normal template without change and normal template with change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 10:54 PM
@Priya75 Make use of OOB Array Util script include paste the snippet below
var au = new global.ArrayUtil();
var templatewithoutchg = au.diff(chgfoundNomraltemp,allNormaltemp);
gs.print(templatewithoutchg);
Mark this as Helpful / Accept the Solution if this clears your issue