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

Instead of addInfomessage please try alert.

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.

AMan1997
Tera Guru

Hi @robholyhead ,

Please refer to the below post, it is a known issue and this may provide a workaround for you:
Catalog Client Scripts for order guides do not work in Service Portal 

 

Thanks,

Hi, 

onsubmit client script works on catalog item but did not work order guide.

Its simple checking of field value if its empty it should not submit. ( For related answer field is readonly that time the field value come as empty).

While trying to solve this issue came across https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0689536 this article.which Aman mentioned

 

Trying to open it but I am getting this error,"This article is available for logged in users. Please Login here" 

Even tried through HI Portal credentials. None is working.

@Saurav11 can you help?other than Mandatory(because mandatory and ready only can't work at same time)

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.