- 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 09:56 AM
Jahanzab, Try the following code
- function confirmCancel(){
- var answer=confirm("Are you sure you want to cancel this record?");
- if (answer==true)
- {
- moveToCancel();
}
else
{
- // 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;
- }
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2017 10:33 AM
Madhsusudana,
Thank you for the response. The option to exit without canceling change request works find and displays alert "This change was not cancelled". Stil not executing the change request cancel when selecting OK. After this failed, I added an alert to the moveToCancel function, but the alert is not displayed. Here is the final code.
Here is the final code.
Let me know if I am still missing something here with the script?
Thanks again,
Jahanzeb
function confirmCancel(){
var answer=confirm("Are you sure you want to cancel this record?");
if (answer==true)
{
moveToCancel();
}
else
{
// 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;
}
}
function moveToCancel(){
action.setRedirectURL(current);
if (new ChangeRequestStateHandler(current).moveTo("canceled"))
current.update();
alert('This change has been cancelled');
}
lled');
}
Madhusudana Golla wrote:
Jahanzab, Try the following code
- function confirmCancel(){
- var answer=confirm("Are you sure you want to cancel this record?");
- if (answer==true)
- {
- moveToCancel();
}
else
{
- // 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;
- }
- }
- 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 10:13 AM
This code will work for you.
You want to invoke the moveToCancel() function via gsftSubmit method if user confirms for cancellation.
gsftSubmit will ignore or skill the onClick function, in your case confirmCancel() and execute the server side function.