UI Action button for Approve on a form

Ross Garvie1
Tera Expert

Hi All,

 

I have a requirement to add an Approve button to a form.  The records related to this form require an approval from two users before the approval state moves to approved.  I have added a UI Action to create the Approval button on the form with the following script:

action.setRedirectURL(current);
current.update();

updateRecord();

function updateRecord(){

var rec = new GlideRecord('sysapproval_approver');

rec.addQuery('sysapproval', current.sys_id).addOrCondition('document_id', current.sys_id);

rec.query();

if(rec.next()){

rec.state = 'approved';

rec.update();

}

}

The approval button works fine for the first user that approves but when the second user approves the approval state for the second user does not update and remains in a Requested state.

If anyone has an idea why this is happening and how to resolve it I would be very appreciative!

Regards,

Ross

5 REPLIES 5

amitrajgrihar
Tera Contributor

Just add additional query for state. 

 

function updateRecord() {
    var rec = new GlideRecord('sysapproval_approver');
    rec.addQuery('sysapproval', current.sys_id).addOrCondition('document_id', current.sys_id);
    rec.addQuery("state", "requested");
    rec.query();
    if (rec.next()) {
        rec.state = 'approved';
        rec.update();
    }
}