- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 05:48 PM
Hi everyone,
I've got a form that requires approval from specific users in certain states. If the issue is in state X and substate Y, and the user = approver1, they should see Approve/Reject/Cancel buttons. Each time an approver approves or rejects the issue, the state/substate will change, and the visibility of the buttons should change accordingly. The Approve/Reject/Cancel buttons have conditions that evaluate the status, substate and user to determine visibility.
In the backend, everything updates correctly. However, from the user's perspective, the form updates, but the buttons remain visible. If I refresh the page manually, everything displays as expected.
Theoretically, we try to refresh the page after doing the action using the following code:
current.update();//update the record
action.setRedirectURL(current);//Refresh the page
I was expecting this to refresh the page, recheck the UI Action's condition, and hide the buttons, but it is not achieving this.
Can anyone help with this? I could tell the users to just wait and refresh the page, but I'm hoping to make it smooth and dodge the complaints entirely.
Relevant questions:
1 - When are UI Action conditions evaluated?
2 - Can I force UI Action conditions to be re-evaluated?
3 - Are there ways to change the visibility of the buttons besides the UI action's condition?
I can provide examples if required.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 06:06 PM
Your script looks good to me!
There is a method in ServiceNow, "gs.sleep(microseconds)" , but it is not a recommended to use in the scripts
Also you can check this link
Can you try one thing, instead of calling the script include paste the code in UI action itself and try again
function serverMoveApprovalState()
{
//Driving the Approval Flow Through UI Action For Approve
var rec = new GlideRecord('sysapproval_approver');
rec.addQuery('state','requested');
rec.addQuery('approver',gs.getUserID());
rec.addQuery('sysapproval', current.sys_id).addOrCondition('document_id', current.sys_id);
rec.query();
if(rec.next()){
rec.state = 'approved';
rec.update();
}
if(current.state=='0' && current.u_substate=='55' && current.u_validator=='')
{
current.u_validator=gs.getUserID();
}
current.update();
action.setRedirectURL(current);
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 06:06 PM
Your script looks good to me!
There is a method in ServiceNow, "gs.sleep(microseconds)" , but it is not a recommended to use in the scripts
Also you can check this link
Can you try one thing, instead of calling the script include paste the code in UI action itself and try again
function serverMoveApprovalState()
{
//Driving the Approval Flow Through UI Action For Approve
var rec = new GlideRecord('sysapproval_approver');
rec.addQuery('state','requested');
rec.addQuery('approver',gs.getUserID());
rec.addQuery('sysapproval', current.sys_id).addOrCondition('document_id', current.sys_id);
rec.query();
if(rec.next()){
rec.state = 'approved';
rec.update();
}
if(current.state=='0' && current.u_substate=='55' && current.u_validator=='')
{
current.u_validator=gs.getUserID();
}
current.update();
action.setRedirectURL(current);
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 09:41 AM
Hey Prince, thanks for your help. your suggestion did help but we ended up re-working the whole flow anyway.