Create an approval record from a UI Action

cczmax
Tera Contributor

Hi, I am trying to create an approval record from a script in a UI Action, but I cannot get it to create with all the field values submitted.

 

When I run the following script from the UI action it creates the approval record but only sets fields ‘state’ and ‘source_table’ and as such it does not appear in the ‘Approvers’ related list in the Incident form that the UI action script was run from.

 

var approval = new GlideRecord('sysapproval_approver');

approval.initialize();

approval.state = 'requested';

approval.approver = '76634a3987730110d96d1f4bbbbb3564'; //users sys_id who should approve

approval.source_table = 'incident';

approval.document_id = '9d385017c611228701d22104cc95c371'; // sys_id of Incident

approval.sysapproval = '9d385017c611228701d22104cc95c371'; //sys_id of initiating Incident

approval.insert();

 

When I run the same above script in ‘scripts – background’, it creates the approval record correctly and links it to the Incident record in the Approvers related list.

 

Am I missing something here.  I know you can use the Edit button on the ‘Approvers’ related list tab to pick and add an approver but wanted to see if this could be done via a script so I can perform additional actions via the script later.

 

Many thanks

Max

1 ACCEPTED SOLUTION

KB18
Tera Guru
Tera Guru

Hi, 

It is working for me. please find the below screen shot.

KB18_0-1683107010992.png

 

KB18_1-1683107038526.png

Please let me know in case any issues.

 

Thanks,
Kailas Bandiwar 

 

Please hit the thumb Icon and mark as correct in case I help you with your query!!!
- Kailas

View solution in original post

4 REPLIES 4

KB18
Tera Guru
Tera Guru

Hi, 

It is working for me. please find the below screen shot.

KB18_0-1683107010992.png

 

KB18_1-1683107038526.png

Please let me know in case any issues.

 

Thanks,
Kailas Bandiwar 

 

Please hit the thumb Icon and mark as correct in case I help you with your query!!!
- Kailas

cczmax
Tera Contributor

Hi Kailas, thank you so much for your reply.  They say a picture paints a thousand words and in this case yours did.

 

Looking at the image you provided I compared it to mine and noticed you had the client tick box unchecked.  For some reason in the back of my mind I took this to mean trigger the execute from the client not run the content within server side as it contains serverside API's.

 

Forgive me, I am new to ServiceNow.  A tick box got me.  Will never forget this one.

Max

Hi Max,

I do understand but you will write Client UI Action with GlideRecord, it is not the best practice. Better to generate Approaval, server-side option is good with no performance issue. 

 

Please hit the thumb Icon and mark as correct in case I help you with your query!!!
- Kailas

KB18
Tera Guru
Tera Guru

Hi, 

It is working for me. please find the below screen shot.

KB18_0-1683107010992.png

 

KB18_1-1683107038526.png

Please let me know in case any issues.

 

Thanks,
Kailas Bandiwar 

 

Please hit the thumb Icon and mark as correct in case I help you with your query!!!
- Kailas