
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 01:36 AM
Hi ALL,
I want to set a field value(string) in approval table by using runscript in Workflow. I wrote one runscript but it did not works. Guys, please have a look once.
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
gr.query();
if(gr.next()){
gr.u_approval_type='First leval Approval';// u_approval_type is a field name
}
Regards,
Rakhesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 04:16 AM
Erm, from what I see right now - you are trying to execute the script before actually creating the approval. Could you perhaps try to swap the places of the Run Script activity and the Approval activity and see what your logs log then? It just seems like you're trying to edit the record before actually creating it 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 01:42 AM
Hey,
The script looks fine, however you are forgetting to actually update after making the changes, add gr.update() after setting the approval level as so:
if(gr.next()){
gr.u_approval_type='First leval Approval';// u_approval_type is a field name
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 01:49 AM
thanks for the response.
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
gr.query();
if(gr.next()){
getapprovar.u_approval_type='First level Approval';
gr.update();
gs.log("TEST FOUND APPROVAL RECORD : " + gr.sysapproval);
}
i tried the above code.still no luck.It was in RUNSCRIPT.even logs also not showing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 02:10 AM
Where did the getapprovar.u_approval_type line come from? Also, sysapproval isn't a field on the sysapproval_approver table so query condition isn't going to match anything. Try the script below, check the number of records returned in your query, if there are multiple approvals you might want to loop through them with 'while' instead of 'if' and update them all.
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', current.sys_id);
gr.query();
gs.log('found ' + gr.getRowCount() + ' records');
if(gr.next()){ //change this line to while(gr.next()){ to loop through records
gs.log("TEST FOUND APPROVAL RECORD");
gr.u_approval_type='First level Approval';
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 02:18 AM