- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2019 09:28 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2019 09:36 AM
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
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2019 09:36 AM
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
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2019 08:29 PM
Hi Harsha,
So what was the exact error here why it was not working?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader