- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 07:00 PM
I have created an UI Action "Cancel Request" button as per below in the requested item table and I want to add the existing scripts when the assignee clicks on the UI Action "Cancel Request" button it will force or set a mandatory to fill in the close notes comment.
How can I do script it and thank you.
Condition
current.approval == 'requested'
Scripts
current.state = '4';
current.approval = 'Cancelled';
current.update();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 07:28 PM
Hi TMKAM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 10:11 PM
Hi @TMKAM ,
try below script and give action name as reject_action and select Client check box.
Give onClick function name as reject() or any name must use same function on script.
function reject() {
g_form.setMandatory('close_notes', 'true');
var answer = confirm("Are you sure you want to Cancel Request?");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'reject_action'); //MUST call the 'Action name' set in this UI Action
} else {
return false;
}
}
if (typeof window == 'undefined') {
current.state = '4';
current.approval = 'Cancelled';
current.setWorkflow(false);
current.update();
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 07:28 PM
Hi TMKAM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 07:47 PM
thank you for your solution and it is working as expected but how do I add a message to inform the assignee to put the message in the close notes.
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 09:42 PM
Hi TMKAM,
Refer this article: https://servicenowguru.com/scripting/ui-info-error-message-cheat-sheet/
Regards,
Pethum
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 10:11 PM
Hi @TMKAM ,
try below script and give action name as reject_action and select Client check box.
Give onClick function name as reject() or any name must use same function on script.
function reject() {
g_form.setMandatory('close_notes', 'true');
var answer = confirm("Are you sure you want to Cancel Request?");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'reject_action'); //MUST call the 'Action name' set in this UI Action
} else {
return false;
}
}
if (typeof window == 'undefined') {
current.state = '4';
current.approval = 'Cancelled';
current.setWorkflow(false);
current.update();
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar