
- 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 02:23 AM
If the workflow is running on the RITM table then you should be able to reference the current.sys_id in the glide query. Put an initial gs.log to confirm the workflow is reaching the run script activity and what the current record is:
gs.log('run script activated!');
gs.log('this is the current record: ' + current.number);
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:34 AM
gs.log('run script activated!');
gs.log('this is the current record: ' + current.number);
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', current.sys_id);
gs.log('query checking!!');
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();
}
i tried the above code. here, 4 logs are coming. but inside of the if condition log is not coming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 02:39 AM
OK so the run script is triggering and the glide query is running, all good. Is it returning the current.number you are expecting? If so, also good, if not that's a problem.
How many records is it saying are being returned in the glide query? should be the 4th log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 02:11 AM
getapprovar.u_approval_type='First level Approval';
^ this line should be modified to be:
gr.u_approval_type = 'First level Approval';
On a side note, if there is nothing logged (even just 'TEST FOUND APPROVAL RECORD : '), there is a chance that the approval has not yet been registered. Is the workflow running on the approvals table? If it is running on any other table, for instance request, requested item or whatever - perhaps try to modify the query to be as follows:
gr.addQuery('document_id', current.sys_id);
But that's a wild guess, if you'd like - provide some context on your task so that we know better what you're delaing with 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 02:20 AM
hi,
I tried this one also. it did not work for me.