Updating sysapproval_approver table in UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2013 05:04 AM
In our form we have 'Request Approval' button. When user clicks this button what are all the approval
records with state = 'Request Approval' has to be updated with state = 'requested'. For this we added below code in 'Request Approval' action.
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id',current.sys_id);
gr.query();
while(gr.next()){
gs.print("State :"+gr.state );
if(gr.state == 'Request Approval'){
gs.print("gr.state in if :"+gr.state );
gr.state = 'requested';
}
gr.update();
gs.print("gr.sys_id : "+gr.sys_id );
}
current.u_mr_state = '2';
current.approval='requested';
current.update();
action.setRedirectURL(current);
This while loop is not working properly. It's going through the approval records one by one, once the approval record with state = 'Request Approval' is come and changing it's state to 'requested' and then updates this record. After this it's showing this print statement 'gs.print("gr.sys_id : "+gr.sys_id );' also, but it's not going to nex record in the loop and control is comming out of the loop. I don't understand what will be the problem here, even if we have more than one approval record with 'Request Approval' state it updating only one remaining are still showing wit 'Request Approval' state.
I verified the logs also, it's showing execution of before and after business rules on 'sysapproval_approver' including 'Approval Events (Task)' business rule.
Could some one tell me what will be the problem here?why it's not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2013 08:45 AM
I suspect that your variable gr is getting stepped on by another business rule when the gr.update() is called. Inspect all the business rules getting called as a result of the update for unprotected references to gr.
In any business rule, you should place the code inside a function call to prevent variables from stepping on one another.
do_the_thing();
function do_the_thing() {
var gr = new GlideRecord('your_table'); // now the scope is local
//etc., etc.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2016 02:43 AM
Perfect answer...!!
I exactly come across this issue and this suggestion solved my issue.
Regards
HB