
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 04:09 AM
I am trying to write a server side code step to approve a record in the sysapproval_approver table.
I am new to ATF hence would require help to write this server side code.
Before you ask why I am using server side code instead of record update or UI action, the answer is it does not work due to customizations.
I am able to open the existing approval record in the previous step. I know we have to utilize the step sys_id somewhere hence notified you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 04:28 AM
Hi,
In Server Side Script you can just query the approval table and approve the current record as below:
var grApprov = new GlideRecord('sysapproval_approver');
// Sys Id of the Change
grApprov.addQuery('document_id',steps('076e2301db2113048812644a4b961976').record_id); //This is your step sysid where you have sys id of record to be approved.
// Sys id of my user
grApprov.addQuery('approver','cb8e5a8cdbb153008812644a4b96195b');
grApprov.query();
if (grApprov.next())
{
grApprov.state = 'approved';
grApprov.update();
}
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 04:28 AM
Hi,
In Server Side Script you can just query the approval table and approve the current record as below:
var grApprov = new GlideRecord('sysapproval_approver');
// Sys Id of the Change
grApprov.addQuery('document_id',steps('076e2301db2113048812644a4b961976').record_id); //This is your step sysid where you have sys id of record to be approved.
// Sys id of my user
grApprov.addQuery('approver','cb8e5a8cdbb153008812644a4b96195b');
grApprov.query();
if (grApprov.next())
{
grApprov.state = 'approved';
grApprov.update();
}
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 05:02 AM
HI,Thank you. I think i am almost there, but in this line step:
grApprov.addQuery('document_id',steps('076e2301db2113048812644a4b961976').record_id); //This is your step sysid where you have sys id of record to be approved.
what type os step it has to be ? A record query step?
I am not able to fetch the sys_id of the actual record from the step sys_id

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 05:16 AM
HI,
Sys id is from record insert step.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 04:29 AM
Hi,
you can use Run Server Side Script step; get the output of previous step in this step; query the record and update it
sample script below; if you are using record query step previous to this then use
steps('sys_id').first_record
(function(outputs, steps, stepResult, assertEqual) {
// add test script here
var tableRec = new GlideRecord('sysapproval_approver');
tableRec.get(steps('sys_id').first_record);
tableRec.state = 'approved';
tableRec.update();
outputs.table = 'sysapproval_approver';
outputs.record_id = tableRec.sys_id;
stepResult.setOutputMessage("Successfully updated record");
stepResult.setSuccess();
return true;
})(outputs, steps, stepResult, assertEqual);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader