Fix script not running , nor the progress window shows after clicking run script

Harsha54
Kilo Contributor

var count1 = 0;
var count2 = 0;
var count3 = 0;

var grRITM1 = new GlideRecord('sc_req_item');
grRITM1.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=complete^state=3^approval!=approved');
grRITM1.setLimit(1);
grRITM1.setWorkflow(false);
grRITM1.query();
while(grRITM1.next()){
count1++;
grRITM1.approval = 'approved'; // Set Approval = Approved
grRITM1.update();
}

var grRITM2 = new GlideRecord('sc_req_item');
grRITM2.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=complete^state!=3');
grRITM2.setLimit(1);
grRITM2.setWorkflow(false);
grRITM2.query();
while(grRITM2.next()){
count2++;
grRITM2.state = '3'; // Set State = Closed Complete
grRITM2.update();
}

var grRITM3 = new GlideRecord('sc_req_item');
grRITM3.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=Request Cancelled^state!=1500^approval!=rejected');
grRITM3.setLimit(1);
grRITM3.setWorkflow(false);
grRITM3.query();
while(grRITM3.next()){
count3++;
grRITM3.approval = 'rejected'; // Set Approval = Rejected
grRITM3.state = '1500'; // Set state = Rejected
grRITM3.update();
}
gs.log('hbigddar Count of RITM records which got updated with Approval value as Approved = '+count1);
gs.log('hbigddar Count of RITM records which got updated with State value as Closed Complete = '+count2);
gs.log('hbigddar Count of RITM records which got updated with Approval value as rejected and State is rejected = '+count3);

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

Hi Harsha,

How many records are there in sc_req_item that you are trying to update through those 3 scripts?

Can you try to update the code as below and try once; I have added try catch block to catch the error

try{

gs.log("Fix Script Started");
var count1 = 0;
var count2 = 0;
var count3 = 0;

var grRITM1 = new GlideRecord('sc_req_item');
grRITM1.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=complete^state=3^approval!=approved');
grRITM1.setLimit(1);
grRITM1.setWorkflow(false);
grRITM1.query();
while(grRITM1.next()){
count1++;
grRITM1.approval = 'approved'; // Set Approval = Approved
grRITM1.update();
}

var grRITM2 = new GlideRecord('sc_req_item');
grRITM2.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=complete^state!=3');
grRITM2.setLimit(1);
grRITM2.setWorkflow(false);
grRITM2.query();
while(grRITM2.next()){
count2++;
grRITM2.state = '3'; // Set State = Closed Complete
grRITM2.update();
}

var grRITM3 = new GlideRecord('sc_req_item');
grRITM3.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=Request Cancelled^state!=1500^approval!=rejected');
grRITM3.setLimit(1);
grRITM3.setWorkflow(false);
grRITM3.query();
while(grRITM3.next()){
count3++;
grRITM3.approval = 'rejected'; // Set Approval = Rejected
grRITM3.state = '1500'; // Set state = Rejected
grRITM3.update();
}
gs.log('hbigddar Count of RITM records which got updated with Approval value as Approved = '+count1);
gs.log('hbigddar Count of RITM records which got updated with State value as Closed Complete = '+count2);
gs.log('hbigddar Count of RITM records which got updated with Approval value as rejected and State is rejected = '+count3);

gs.log("Fix Script Ended");
}
catch(ex){
gs.log("Error Message is" + ex);
}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron

Hi Harsha,

How many records are there in sc_req_item that you are trying to update through those 3 scripts?

Can you try to update the code as below and try once; I have added try catch block to catch the error

try{

gs.log("Fix Script Started");
var count1 = 0;
var count2 = 0;
var count3 = 0;

var grRITM1 = new GlideRecord('sc_req_item');
grRITM1.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=complete^state=3^approval!=approved');
grRITM1.setLimit(1);
grRITM1.setWorkflow(false);
grRITM1.query();
while(grRITM1.next()){
count1++;
grRITM1.approval = 'approved'; // Set Approval = Approved
grRITM1.update();
}

var grRITM2 = new GlideRecord('sc_req_item');
grRITM2.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=complete^state!=3');
grRITM2.setLimit(1);
grRITM2.setWorkflow(false);
grRITM2.query();
while(grRITM2.next()){
count2++;
grRITM2.state = '3'; // Set State = Closed Complete
grRITM2.update();
}

var grRITM3 = new GlideRecord('sc_req_item');
grRITM3.addEncodedQuery('configuration_item.operational_status=7^cat_item.name=Retire Business Application^stage=Request Cancelled^state!=1500^approval!=rejected');
grRITM3.setLimit(1);
grRITM3.setWorkflow(false);
grRITM3.query();
while(grRITM3.next()){
count3++;
grRITM3.approval = 'rejected'; // Set Approval = Rejected
grRITM3.state = '1500'; // Set state = Rejected
grRITM3.update();
}
gs.log('hbigddar Count of RITM records which got updated with Approval value as Approved = '+count1);
gs.log('hbigddar Count of RITM records which got updated with State value as Closed Complete = '+count2);
gs.log('hbigddar Count of RITM records which got updated with Approval value as rejected and State is rejected = '+count3);

gs.log("Fix Script Ended");
}
catch(ex){
gs.log("Error Message is" + ex);
}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Ankur Bawiskar
Tera Patron

Hi Harsha,

So what was the exact error here why it was not working?

Regards

Ankur