- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2023 09:31 PM
Hi,
We had a cancel button for "dmn_demand" table to cancel the record by change the state->cancel.
I want to add a confirm message before cancelling the record. So I changed the script from
current.state = 10;
current.update();
action.setRedirectURL(current);
To:
function cancelRecord() {
var st = g_form.getValue('state');
g_form.setValue('state', 8);
var answer = confirm('Are you sure you want to cancel this record?');
if (answer != true) {
g_form.setValue('state', st);
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'cancel');
}
if (typeof window == 'undefined')
serverResolve();
function serverResolve() {
current.state = '10';
current.update();
action.setRedirectURL(current);
}
I checked "True" to client check box & added the client function name to "onclick" field.
But the problem is, the client side is running, but the server side is not running.
I am getting confirm box, but after click on this, the state is not changing to cancel, and page is not redirecting to same page.
Anyone please help me on this, what could be the peoblem!!!!!!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 02:04 AM
Are you sure in the Action name you entered "cancel"
why are you setting the state value in client side when you are already setting it in server side?
Update as this
function cancelRecord() {
var answer = confirm('Are you sure you want to cancel this record?');
if (answer != true)
return false;
else
gsftSubmit(null, g_form.getFormElement(), 'cancel');
}
if (typeof window == 'undefined')
serverResolve();
function serverResolve() {
current.state = '10';
current.update();
action.setRedirectURL(current);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 06:45 AM
Can you change the action name and try.
Thanks,
Rahul Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 06:45 AM
Can you change the action name and try.
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 07:02 AM
Awesome, good guess, the conflict was happening for action name.
Now it started working.
Thank you very much!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 02:04 AM
Are you sure in the Action name you entered "cancel"
why are you setting the state value in client side when you are already setting it in server side?
Update as this
function cancelRecord() {
var answer = confirm('Are you sure you want to cancel this record?');
if (answer != true)
return false;
else
gsftSubmit(null, g_form.getFormElement(), 'cancel');
}
if (typeof window == 'undefined')
serverResolve();
function serverResolve() {
current.state = '10';
current.update();
action.setRedirectURL(current);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 06:11 AM
Hi Ankur,
yeah, the action name is "cancel" & onclick as "cancelRecord();".
But something is wrong, the server side code is not running.
Once I click "ok" on confirm message, the page is refreshing, but the state is not changing.
The reason I could not find.
Thank you !!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 08:06 AM
did the confirm box come?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader