action.setRedirectURL(current) is not working with List context menu UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 09:26 AM
Hello experts,
I am trying to create a List context menu UI action; Comments should be mandatory when rejecting an approval from List context menu. I have tried the below but, when I say 'action.setRedirectURL(current)' it should be redirected to Approval record, but it is on the same change request form. Could you please help me on this?
Name: Reject
Table: Approval [sysapproval_approver]
List Context Menu: Checked
Condition: ootb
Script:
current.state = 'rejected';
if (!gs.nil(current.comments.getJournalEntry(-1))) {
current.update();
new ApprovalUserFeedback().rejected(current);
} else {
gs.addErrorMessage(gs.getMessage("Comments are required when rejecting an approval"));
current.state = 'requested';
current.setAbortAction(true);
action.setRedirectURL(current);
}
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 09:39 AM
To redirect to the approval record after the "Reject" UI action is executed, you can try the following changes to your script:
1. After setting the current.state to 'rejected', retrieve the approval record related to the current approval task using the current.getRelatedRecord() function. For example:
current.state = 'rejected';
var approval = current.getRelatedRecord();
- Instead of using
action.setRedirectURL(current)
, useaction.setRedirectURL(approval)
to redirect to the approval record.
if (!gs.nil(current.comments.getJournalEntry(-1))) {
current.update();
new ApprovalUserFeedback().rejected(current);
action.setRedirectURL(approval);
} else {
gs.addErrorMessage(gs.getMessage("Comments are required when rejecting an approval"));
current.state = 'requested';
current.setAbortAction(true);
action.setRedirectURL(current);
}
This should redirect to the approval record after the "Reject" UI action is executed, rather than staying on the same change request form.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 11:47 PM
Hi @Gunjan Kiratkar, Thank you for your suggestion.
I tried the above code, which is not working, throwing the below as redirection undefined.
So, I tried the below code, and it is working only for successful condition. If I try the same approach in else condition, it reloading same Change request form only.
current.state = 'rejected';
//var approval = current.getRelatedRecord();
id = current.sys_id;
if (!gs.nil(current.comments.getJournalEntry(-1))) {
current.update();
new ApprovalUserFeedback().rejected(current);
if (typeof window == 'undefined')
redirectHere(); //change to next stage
} else {
gs.addErrorMessage(gs.getMessage("Comments are required when rejecting an approval"));
current.state = 'requested';
current.setAbortAction(true);
}
function redirectHere() {
action.setRedirectURL('/nav_to.do?uri=sysapproval_approver.do?sys_id='+id);
}
But I need this redirection for else condition, when the approver is rejecting without comments, we need to redirect to the approval record to add the comments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 06:59 AM
hi nithin,
I have the similar requirement , did you find an way to redirect to the approval record when the approval is rejected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 07:01 AM
@Nithin_kumar please reply if you have the solution , thanks.