catalog client script to prevent the submission of the catalog form.

phr
Tera Contributor

Hi All,

 

I have a requirement when the below option is selected i need to present the error message on the catalog item that should present the user from submitting it.

Below is the script that i wrote:-

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var sn = g_form.getValue("do_you_already_have_visual_studio_license");
if (newValue == "no" || sn == 'no') {

g_form.addErrorMessage("Please add GitHub Enterprise license to the service required field in this form");("Please add GitHub Enterprise license to the service required field in this form");
}
}

 

Its throwing the error message . But i am able to submit the catalog item. 

How to prevent the submission of the catalog item when the error message is presented.

How to achieve this?

 

(Note: I did use the OnSubmit as well, still i am able to submit the form)

 

 

2 ACCEPTED SOLUTIONS

Siddhesh Wani1
Tera Guru

To achieve this requirement please use the on submit client script. 
Check the variable and add the error message 

 

var sn = g_form.getValue("do_you_already_have_visual_studio_license");
    // alert(sn);
    if (sn == "no") {
        g_form.addErrorMessage(getMessage("Please add GitHub Enterprise license to the service required field in this form"));
        return false;
    } else {
        return true;
    }

View solution in original post

Jitendra Diwak1
Kilo Sage

Hi @phr,

 

Please check this below thread. 

https://www.servicenow.com/community/itsm-forum/onsubmit-client-script-to-prevent-form-submission/m-... 

 

Please accept my solution if it resolves your issue and thumps 👍 up 

 

Thanks 

Jitendra 

Please accept my solution if it works for and thumps up.

View solution in original post

3 REPLIES 3

Siddhesh Wani1
Tera Guru

To achieve this requirement please use the on submit client script. 
Check the variable and add the error message 

 

var sn = g_form.getValue("do_you_already_have_visual_studio_license");
    // alert(sn);
    if (sn == "no") {
        g_form.addErrorMessage(getMessage("Please add GitHub Enterprise license to the service required field in this form"));
        return false;
    } else {
        return true;
    }

Hi @Siddhesh Wani1 

 

Thank you, it worked.

Jitendra Diwak1
Kilo Sage

Hi @phr,

 

Please check this below thread. 

https://www.servicenow.com/community/itsm-forum/onsubmit-client-script-to-prevent-form-submission/m-... 

 

Please accept my solution if it resolves your issue and thumps 👍 up 

 

Thanks 

Jitendra 

Please accept my solution if it works for and thumps up.