Confirm box (Yes/No) in a UI Action

hongsok
Tera Contributor

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

8 REPLIES 8

@hongsok 

Please update script as this and test once

function confirmAndTransferFromForm() {

var usrResponse = confirm('Are you sure you want to transfer this request to incident?');
if (usrResponse.toString() == '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);
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

 toString() or the script which i have mentioned that will also work.

Updated script 

 

function confirmAndTransferFromForm() {

	var usrResponse = confirm("Are you sure you want to transfer this request to incident?");

	if (!usrResponse) {
		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);
}

 

If my answer helped you, kindly mark it as correct and close this thread. 

 

Community Alums
Not applicable

Change createGSTicket1(); to somethinbg like:

 

function createGSTicket1(){

    g_form.setValue("transf_inc ", "true");

//add all you fields required in similar manner as above

    g_form.save();

}

 

This will allow you to save the values from the client side

 

P.S. Ahhh I see what you mean 🙂 You better use UI Page for that and call it by GlideDialog(). Then its easy. Take a look for GlideDialog examples (in UI Pages try with something like *yes or *confirm). Then you'll get it

Try this:

 

 

 

Cheers,

Joro

are you in Global scope or custom scope? The windows dialog code are different depend on the scope.