How can I add an approval button in a form

Juliette1
Tera Contributor

Hi everyone, 

I need to add a button in a form.

the user see the record he can approve or reject.

I am new to servicenow and I am not really sure of how to do it.

 

Thanks for your help

Juliette

1 ACCEPTED SOLUTION

Hi,

got it

Try this code in the UI action of Approve on your custom Table; It should be server side

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();

}

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You will have to create Form UI Action

Condition: gs.getUserID() == current.approver_field

This will allow them to see the button only if the logged in user is approver

In the script section set the state to Approve/Reject based on your UI Action and then update the record

Refer OOB UI Actions Approve and Reject on sysapproval_approver table

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Juliette1
Tera Contributor

Thank you for your Answer Ankur Bawiskar but I am not really a developer and not used to write any script

 

Hi,

Refer these Out of the box UI actions; they should help you in the scripting

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Juliette1
Tera Contributor

Thank you for your second answer, the thing is the approve action are set inside the approval table... my button is inside another table and when we click the button, we need to change the requested state of the approval in the sys_approval table in Approved.... Is it possible??

 

Thank you again

Best Regards

Juliette