alert modal out of box got it button not working

ahmed786
Tera Contributor

Hi All,

The alert modal out of box got it button is not working in the UI builder.  The behavior is not consistent, I have 3 alerts modals, one for select location, second one for billing profile and third one for network coverage, the configuration and events are same except message.  It is working for second and third and first one it is not working.  I have created the script to invoke this in the above sequence, it is not working for first one.  Following is the script.  Below is the script that invoke the alert modal from the button.

 

/**
 * @Param {params} params
 * @Param {api} params.api
 * @Param {any} params.event
 * @Param {any} params.imports
 * @Param {ApiHelpers} params.helpers
 */
function handler({
    api,
    event,
    helpers,
    imports
}) {
    //If location is not selected, error message will be displayed
    if (!api.state.contextFilterChanges.contextFields["location"]) {
        helpers.modal.open('select_location');
        return;
    }
    var permittedBillingProfile = event.payload.data.output;
    let productData = {
        "productId": permittedBillingProfile.productOfferingSysId,
        "quantity": 1,
        "contextFilterChanges": api.state.contextFilterChanges
    };
        // check for permitted billing profile and type Network Coverage
        if (permittedBillingProfile.isPermitted == true && permittedBillingProfile.hasNetworkCoverage == true) {
            api.emit('SN_PRODUCT_CATALOG#CUSTOMIZE', {
                productData: productData,
                catalogType: api.state.requestEntityDetails.catalogType
            });

       } else if (permittedBillingProfile.isPermitted == false) {
            helpers.modal.open('select_billing_account');
        } else {
          helpers.modal.open('network_coverage_undefined');
        }
}
1 REPLY 1

Vishal Jaswal
Tera Sage

Hello @ahmed786 

helpers.modal.open -> you can only display one modal at a time. If a modal is currently open, opening another hides the previous one: https://www.servicenow.com/docs/r/washingtondc/api-reference/ui-builder-api-reference/helpersAPI.htm... 

What happens here is:

 

helpers.modal.open('select_location'); // alert opens
User clicks Got it
Modal UI disappears 
Modal framework still thinks a modal is open 
Next time a modal is requested → ignored silently

Why the other two work:

 

They occur after an emit / rerender
UI Builder context refresh partially resets modal state

 


So better to use a Confirm Modal as explained here: https://www.servicenow.com/community/next-experience-blog/ui-builder-essentials-modals-and-modeless-... 


Hope that helps!