How to close GlideModal from Client Side without button click

Community Alums
Not applicable

I need close Progress Modal and show Confirmation Modal without button click after getting response from Script Include. Using GlideAjax. Any Suggestions...?

Abdullah10_0-1723981201596.png

 

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hello @Community Alums 

This is achievable. I tried this in my PDI which is working fine. Try to replicate the same in your instance.

Quick overview:
In my script I'm checking whether user is VIP or not. If the user is VIP, destroying the glidemodal after 2 seconds.

Now you can implement the next steps which is confirmation modal.

Here is my code:

 

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

    var gm = new GlideModal("glide_progress_no_button", false, 600);  // initialize and render the GlideModal
    gm.setTitle("User status");
    gm.setPreference("title", "Checking user status");
    gm.setPreference("warning", "false");
    gm.render();

    var gAjax = new GlideAjax('global.IncidentUtil');  // glideAjax call to the server-side script
    gAjax.addParam('sysparm_name', 'getUserDetail');
    gAjax.addParam('sysparm_user', newValue);
    gAjax.getXMLAnswer(function(answer) {
        answer = JSON.parse(answer);
        if (answer.manager == '1') {
            onClose(true);
        } else {
            onClose(false);
        }
    });

    function onClose(value) {   // function to close the modal
        if (value === true) {
            setTimeout(function() {
                gm.destroy(); // destroy the modal after 2 seconds
            }, 2000);
		}

		//Now it's time to write your code from here 
    }
}

 

Quick demo:

UserVIP.gif

 

Hope it helps:)

 

 

Thanks,
Murthy

View solution in original post

3 REPLIES 3

Ravi Peddineni
Kilo Sage

Try using below code in your call back function:

action.setRedirectURL(current)

 Please don't forget to mark helpful if the solution solves the problem

Murthy Ch
Giga Sage

Hello @Community Alums 

This is achievable. I tried this in my PDI which is working fine. Try to replicate the same in your instance.

Quick overview:
In my script I'm checking whether user is VIP or not. If the user is VIP, destroying the glidemodal after 2 seconds.

Now you can implement the next steps which is confirmation modal.

Here is my code:

 

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

    var gm = new GlideModal("glide_progress_no_button", false, 600);  // initialize and render the GlideModal
    gm.setTitle("User status");
    gm.setPreference("title", "Checking user status");
    gm.setPreference("warning", "false");
    gm.render();

    var gAjax = new GlideAjax('global.IncidentUtil');  // glideAjax call to the server-side script
    gAjax.addParam('sysparm_name', 'getUserDetail');
    gAjax.addParam('sysparm_user', newValue);
    gAjax.getXMLAnswer(function(answer) {
        answer = JSON.parse(answer);
        if (answer.manager == '1') {
            onClose(true);
        } else {
            onClose(false);
        }
    });

    function onClose(value) {   // function to close the modal
        if (value === true) {
            setTimeout(function() {
                gm.destroy(); // destroy the modal after 2 seconds
            }, 2000);
		}

		//Now it's time to write your code from here 
    }
}

 

Quick demo:

UserVIP.gif

 

Hope it helps:)

 

 

Thanks,
Murthy

Thanks for this. I have implemented something similar where i utilize the ootb 'loading_dialogue' UI page in a GliceModal, that way when clicking a UI action where the GlideAjax call might take a while, i show the loading UI Page as the first thing, and as soon as the GlideAjax data is ready, i destroy the loading page and then show the new UI Page with the data.

But sometimes both modals would load at the same time, cause the load modal to be behind the other modal, then closing the non loading modal. The loading modal would just sit there and never go away. But this function setup with a timeout stops that from happening 🙂