- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 04:01 AM
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;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 06:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 05:05 AM
Instead of addInfomessage please try alert.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 05:55 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 10:05 AM - edited 09-14-2023 10:06 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 06:16 AM
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.