Confirm box (Yes/No) in a UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2021 12:00 PM
Hello all,
I have created the following UI action and it works fine. Now I have a requirement to add the Confirm box (Yes/No) to that UI Action button.
createGSTicket1();
function createGSTicket1() {
current.transf_inc = 'true';
current.update();
action.setRedirectURL(current);
}
_____________________________________________________________________
Now I add the following code in and the Confirm box is not working.
createGSTicket1();
function createGSTicket1() {
var usrResponse = confirm('Are you sure you want to transfer this request to incident?');
if (usrResponse == true) {
current.transf_inc = 'true';
current.update();
action.setRedirectURL(current);
} else {
return false;
}}
I would appreciate if someone can help me on this issue.
Regards,
Hong
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2021 12:16 PM
confirm() works at client side. you have to use confirm in client side function and update part will be at server side.
Please have a look on below blog for further details about UI Action
https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2021 12:21 PM
Updated Sample code:
//Client-side 'onclick' function
function test(){
var usrResponse = confirm('Are you sure you want to transfer this request to incident?');
if(usrResponse == 'false'){
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'test'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
current.transf_inc = true;
current.update();
gs.addInfoMessage('You did it!');
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 06:34 AM
Hi Harshvardhan,
When I click it does not show the Yes/No confirm box. It's aborted submission. Any idea?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2021 08:37 AM
Hi Harshvardhan,
The confirm box is working and the problem is if I click on either OK or Cancel, the script set the current.transf_inc = true.
Any idea?
____________________________________
function confirmAndTransferFromForm() {
var usrResponse = confirm('Are you sure you want to transfer this request to incident?');
if (usrResponse == 'false') {
return false; //Abort submission
} else
gsftSubmit(null, g_form.getFormElement(), 'transfer_incident'); //Call the Action name set in this UI Action
}
if (typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode() {
current.transf_inc = true;
current.update();
gs.addInfoMessage('You did it!');
action.setRedirectURL(current);
}