- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2017 08:15 AM
SN Team,
In the process of modifying an existing Cancel Change UI Action. The goal is for the new UI Action to provide an confirmation window before proceeding with the Cancel Change request.
I have reviewed the following articles and here is what I came up.
Reference 1:
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Reference 2: Re: Cancel confirm window after clicking cancel button
Main issue: Confirmation window opens fine and allows user to Cancel. Having trouble getting the Cancel Change request to execute when OK is selected.
Looking for some help figuring out how to get the moveToCancel(); function to execute.
//moveToCancel();
//confirmCancel();
function confirmCancel(){
var answer=confirm("Are you sure you want to cancel this record?");
if (answer==false)
{
// gsftSubmit(null, g_form.getFormElement(), 'cancel_change'); //MUST call the 'Action name' set in this UI Action
alert('This change was not cancelled');
return false;
}
else
{
moveToCancel();
return true;
}
}
function moveToCancel(){
action.setRedirectURL(current);
if (new ChangeRequestStateHandler(current).moveTo("canceled"))
current.update();
}
}
Thanks,
Jahanzeb
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2017 10:11 AM
- function confirmCancel(){
- var answer=confirm("Are you sure you want to cancel this record?");
- if (!answer)
- {
- alert('This change was not cancelled');
- return false;
- }
- else
- {
- gsftSubmit(null, g_form.getFormElement(), 'cancel_change'); //MUST call the 'Action name' set in this UI Action
- }
- }
- function moveToCancel(){
- action.setRedirectURL(current);
- if (new ChangeRequestStateHandler(current).moveTo("canceled"))
- current.update();
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2017 11:21 AM
Deepak,
Thanks for the recommendation. This works great now!! I now understand your comment about using the gsftSubmit method if the user confirms the cancellation. Here is what I have for the UI action fields and the Script.
Here is a summary of what I modified on the UI action:
1. Included Action Name: cancel_change
2. Added invoke moveToCancel function on the first line of the script.
The cancellation is successful when the user confirms cancellation. I had to invoke the moveToCancel function outside of the onClick function. Considering best practices for UI actions, do you see any issues with where I invoke moveToCancel?
Just looking into other scenarios. By adding the moveToCancel function on the first line, Is is possible that this will Cancel the change request if the user does not provide any input after 2 attempts?
moveToCancel();
//confirmCancel();
function confirmCancel(){
var answer=confirm("Are you sure you want to cancel this record?");
if (!answer)
{
alert('This change was not cancelled');
return false;
}
else
{
gsftSubmit(null, g_form.getFormElement(), 'cancel_change'); //MUST call the 'Action name' set in this UI Action
}
}
function moveToCancel(){
action.setRedirectURL(current);
if (new ChangeRequestStateHandler(current).moveTo("canceled"))
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2017 02:34 PM
Actually you dont require moveToCancel() function call at all.
You can remove this from line 1
gsftSubmit() calls this function and we are calling gsftSubmit only when user clicks on OK for cancellation.
So you don't require it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2017 06:13 AM
Deepak,
Went through some more testing without the moveToCancel() function call on the first line. The script no longer cancels the Change Request based on this function. The user is returned to the previous screen and the Change Request state does not update. At this point, it appears that there must be some call to moveToCancel() function within the script.
I went back and referenced the out of the box Cancel Change script for UI actions(shown below). This includes a moveToCancel function call even though this is the only function in the script.
Unless there is a better way to call this function, I will have to leave this on the first line,
Thanks again for all of your help.
Regards,
Jahanzeb
moveToCancel();
function moveToCancel(){
action.setRedirectURL(current);
if (new ChangeRequestStateHandler(current).moveTo("canceled"))
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 10:48 PM
Hi Deepak,
i tried same code but when i click on cancel it won't gives popup message and also don't cancel my request.. below is my code for your reference.
let me now if you can help me on this?
cycleMove();
function Cancelconfirm(){
var answer=confirm('are you sure you want to cancel?');
if(answer==true){
gsft.g_form.getSubmit(null,g_form.Element(),'cancel');//my ui action name
}
else{
return false;
}
function cyclemove(){
current.phase='cancelled';
current.active=false;
current.update();
action.SetRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 10:48 PM
Hi Deepak,
i tried same code but when i click on cancel it won't gives popup message and also don't cancel my request.. below is my code for your reference.
let me now if you can help me on this?
cycleMove();
function Cancelconfirm(){
var answer=confirm('are you sure you want to cancel?');
if(answer==true){
gsft.g_form.getSubmit(null,g_form.Element(),'cancel');//my ui action name
}
else{
return false;
}
function cyclemove(){
current.phase='cancelled';
current.active=false;
current.update();
action.SetRedirectURL(current);
}