GlideModal help

Naga Ravindra R
Kilo Sage

Hi there,

 

we have a ui action with following script:

 

function par_req() {
    var gm = new GlideModal("glide_prompt", true, 1600);
    gm.setTitle("Create Product Allocation Requests");
    gm.setPreference("title", "Number of Allocations Required (Max 50)");
    gm.setPreference("onPromptComplete", function(value) {
        g_form.setValue('number_of_product_request', value);
        g_form.save();
        gsftSubmit(null, g_form.getFormElement(), 'add_product_allocation_requests');
    });

    gm.render();
}

 

when user clicks on it, it will show like below:

 

NagaRavindraR_0-1708946046798.png

 

Ideally we are setting the value in a field, That field is of type integer. But If user enters alphabets, we have to show error.
For ex, if user enters 4a, I have to show error saying the please enter only number. Also if user tries to submit, do not let them submit it.

 

Is there any way I can perform the validation in UI action? Any references.

Please let me know. Thank you

1 ACCEPTED SOLUTION

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Naga Ravindra R , 

 

Can you try this 

function par_req() {
    var gm = new GlideModal("glide_prompt", true, 1600);
    gm.setTitle("Create Product Allocation Requests");
    gm.setPreference("title", "Number of Allocations Required (Max 50)");
    gm.setPreference("onPromptComplete", function(value) {
        if (!isNaN(value)) {
            var intValue = parseInt(value, 10);
            if (intValue >= 1 && intValue <= 50) {
                g_form.setValue('number_of_product_request', intValue);
                g_form.save();
                gsftSubmit(null, g_form.getFormElement(), 'add_product_allocation_requests');
            } else {
                alert("Please enter a number between 1 and 50.");
            }
        } else {
            alert("Please enter only numeric values.");
        }
    });

    gm.render();
}

 

Please mark as Accepted as Solution !!!

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

View solution in original post

5 REPLIES 5

Service_RNow
Mega Sage

Hi @Naga Ravindra R 

Follow thread it will be helpful:-

https://www.servicenow.com/community/developer-forum/using-ui-action-with-glidemodal/m-p/2348354 

https://davidmac.pro/posts/2022-02-08-glidemodal/

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

 

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Naga Ravindra R , 

 

Can you try this 

function par_req() {
    var gm = new GlideModal("glide_prompt", true, 1600);
    gm.setTitle("Create Product Allocation Requests");
    gm.setPreference("title", "Number of Allocations Required (Max 50)");
    gm.setPreference("onPromptComplete", function(value) {
        if (!isNaN(value)) {
            var intValue = parseInt(value, 10);
            if (intValue >= 1 && intValue <= 50) {
                g_form.setValue('number_of_product_request', intValue);
                g_form.save();
                gsftSubmit(null, g_form.getFormElement(), 'add_product_allocation_requests');
            } else {
                alert("Please enter a number between 1 and 50.");
            }
        } else {
            alert("Please enter only numeric values.");
        }
    });

    gm.render();
}

 

Please mark as Accepted as Solution !!!

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Hi @Sohithanjan G 

 

The UI action is not resposnding to the code with the code above.

Hi @Naga Ravindra R ,

 

If thats not works somehow, GlidaModal is not supported those capabilities. Instead you can go for an UI page for the same. 

 

BR, Sohiht

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)