How to check all approvals are approved & set incident state to inprogress?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 08:52 AM
Hi All,
Please help me with How to check all approvals are 'approved' & set incident state to in-progress ? and if any one approval is in 'requested' state then incident state should be in 'pending'.
Once Approver is added or any approval is in requested state then — Incident Status is change to 'Pending Approval' and If approval is rejected or approved incident is changed to 'in progress' status.
// tried gliding both approver table & incident table but not working as per expected.
var number = current.sys_id;
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("sysapproval", number);
gr.query();
while(gr.next()) {
var st = gr.state;
if(st == 'approved' || st =='rejected'){
current.state = 2; //in progress
current.update();
}
if(st =='requested') {
current.state = 3; // pending
current.update();
}}
Thank You.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 01:39 PM
Please try following code to check the approval
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("sysapproval", current.sys_id);
gr.query();
if (!gr.hasNext()) {
gs.addInfoMessage("Please add an approver to move to pending approval state");
current.setAbortAction(true);
}
--------------------------------------------------------------------------------------------------
(or)
Try This Code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue=='resolved state value')
{
var gr = new GlideRecord('sysapproval_approver');
gr.query('sysapproval',g_form.getUniqueValue());
gr.query('state','requested');
if(gr.next())
{
alert('your message');
g_form.setValue('state',oldValue);
}
}
}