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

Yousaf
Giga Sage

Hi,

When it runs first time state is already approved right? before the second approver approves 
or am i missing something


***Mark Correct or Helpful if it helps.***

Hi Yousaf,

 

The flow requires approval from all approvers before the state of the record moves to approved.  So currently when the first approver approvers via the button the state or their approval request moves to approved, but when the second approver approves via the button the state of their approval remains "Requested".

So the Approve button is only working as desired for the first approver that approves.

Does that make sense?

Ross

Yes thanks that what I think is the problem after the first approver approves it shouldn't change it to approve. Because if its already approved whats the point of approving of second approver.
I don't think UI Action is a good way to handle this


***Mark Correct or Helpful if it helps.***

Hi Yousaf, 

 

Just add another filter as below and boom.

 

ction.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.addQuery("state", "requested"); --- To get requested item from WF
    rec.query();
    if (rec.next()) {
        rec.state = 'approved';
        rec.update();
    }
}