Double Confirmation Should come when i select status field as reject?

Kruthik M Shiva
Tera Contributor

Hi All,
I have a requirement to pop up confirm if you have to reject the form and two choices should be there in pop up as yes or no if they select as change to reject status else previous status only be set. Please do share what needs to be done for this and if any scripting required please help on that as well.
Thanks in advance.

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Kruthik M Shiva ,

 

Kindly refer below code to achieve your requirement.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if(newValue == 'rejected'){ // please use proper backend name of the reject status

	var answer = confirm('Do you wish to proceed with Rejecting the change');

	if(!answer){
		return false;// this will not allow the user to save the form with reject status
	}

	}

}

 

Please mark my answer helpful & accepted if it helps you resolve your issue.

 

Thanks,

Danish

View solution in original post

17 REPLIES 17

Hello @Kruthik M Shiva ,

 

You need to remove this 3 lines from above code

 

var answer = confirm('Do you wish to proceed with Rejecting the change');

	if(!answer){
		return false;// this will not allow the user to save the form with reject status
	}

 

Instead add below code please & check

 

You can create a Confirmation Modal:

var dialog = new GlideModal('glide_modal_confirm', true, 300);
dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
dialog.setPreference('body', new GwtMessage().format("Your message"));
dialog.setPreference('focusTrap', true);
dialog.setPreference('onPromptComplete', doComplete);
dialog.setPreference('onPromptCancel', doCancel);
dialog.render();

function doComplete() {
    callback(true);
}

function doCancel() {
    callback(false);
}

 

 No need to create a UI Page.

 

Please mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

Hi @Danish Bhairag2 
Do I need to use the above code in the same client script what all i need to change exactly to the above code can you please elaborate?

Hi @Kruthik M Shiva ,

 

Yes u need to update it in the same client script. Just remove those 3 lines which I mentioned in above reply & replace it with 

var dialog = new GlideModal('glide_modal_confirm', true, 300);
dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
dialog.setPreference('body', new GwtMessage().format("Your message")); // mention your message here which u wish to display
dialog.setPreference('focusTrap', true);
dialog.setPreference('onPromptComplete', doComplete);
dialog.setPreference('onPromptCancel', doCancel);
dialog.render();

function doComplete() {
    callback(true);
}

function doCancel() {
    callback(false);
}

Hope this helps you. mark my answer helpful if it helps you resolve your query

 

Thanks,

Danish

Hello @Kruthik M Shiva ,

The confirm() method functionality is a native modal dialog so it'll depend on the browser. In firefox renders the confirm modal differently, It didn't show the title in Firefox.

If you want to hide the title, then need to use a custom modal using GlideModal api.

 

Below is the sample code for GlideModel confirm box

var dialog = new GlideModal('glide_modal_confirm', true, 300);
dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
dialog.setPreference('body', new GwtMessage().format("Your message"));
dialog.setPreference('focusTrap', true);
dialog.setPreference('onPromptComplete', doComplete);
dialog.setPreference('onPromptCancel', doCancel);
dialog.render();

function doComplete() {
    callback(true);
}

function doCancel() {
    callback(false);
}

 

Refer to product docs for GlideModel here

 

Please mark my answer correct and helpful, if it helps you

Thank you

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Hi @RAMANA MURTHY G  and @Danish Bhairag2 ,
I tried but I am getting javascript error in portal for this can you please tell why is that so tried with whatever you mentioned. please let me know if you know the reason.
Thanks