Scheduled job not working as expected

Priya75
Tera Contributor

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

}

 

}

4 REPLIES 4

AnveshKumar M
Tera Sage
Tera Sage

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
  }
}
Thanks,
Anvesh

S Goutham
Tera Guru

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);
            }

 

 

 

I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue

how to segregate the normal template without change and  normal template with change.

 

@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);
I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue