- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2023 11:35 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 02:44 AM
Hi,
It is working for me. please find the below screen shot.
Please let me know in case any issues.
Thanks,
Kailas Bandiwar
- Kailas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 02:44 AM
Hi,
It is working for me. please find the below screen shot.
Please let me know in case any issues.
Thanks,
Kailas Bandiwar
- Kailas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 12:05 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 07:02 PM
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.
- Kailas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 10:37 PM
Hi,
It is working for me. please find the below screen shot.
Please let me know in case any issues.
Thanks,
Kailas Bandiwar
- Kailas