OnSubmit Catalog Client Script not working from Service Portal

robholyhead
Tera Contributor

We have the below script to prevent users from logging a request without values in either of the roles fields. This works using the "try it" functionality, however directly on the portal it does not.

Our request is using an order guide, so not sure if this is the reason?

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var formRoles = g_form.getValue('roles');
    var formIndv = g_form.getValue('individual');
    if (formRoles == '' && formIndv == '') {
        g_form.addInfoMessage('A role must be selected before submitting this request');
        return false;
    }
}

 

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

As Aman correctly pointed out Catalog client script do not work for order guides exactly the way we expect it to work.

 

Rather to achieve your requirement I would do the below:-

 

Make both the field mandatory. As soon as any one field is filled you can make the other field non mandatory and vice versa. This way you will force the user to fill atleast one field.

 

Another way is to create a dropdown which will be mandatory. The options will be roles/individual/both. As this filed will be mandatory they will be forced to use the option base don the option show the fields roles/individual or both field and keep them mandatory so that they have to fill it.

 

Please mark my answer as correct based on Impact.

View solution in original post

8 REPLIES 8

palanikumar
Mega Sage

Hi,

Make sure "All" is selected in "UI Type" drop down of Client script

 

Thank you,

Palani

Thank you,
Palani

Hi There, the UI type is already set to all, any other thoughts?

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @robholyhead ,

This happens due to the UI type type selected as desktop then it will run only for the IT view. If you want to run it on portal or mobile as well select 'all or 'portal/mobile'.

This change will make your client script run on portal as well.

Please mark correct if it helps.
BR,
Nayan

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Hiya, the UI type is already set to all, any other thoughts?