OnSubmit client script to make attachment mandatory in service portal is not running on glideapp

Harsha34
Tera Expert

Hello,

 

I wrote an on submit script to make attachment mandatory that is visible on service portal or esc, but this script is not running on glideapp.servicecatalog_cat_item_view. Below screenshot for your reference. Please suggest .

I have written 2 same on submit script, one for desktop and other for mobile/service portal.

 

This script is working on Service Portal but not on glideapp.

 

When I selected all in catalog client scripts I got below error , so created two separate catalog client scripts.

Harsha34_0-1730198247455.png

 

Script:

 

function onSubmit() {
    if (this.document.getElementsByClassName('get-attachment').length == 0) {
        g_form.addErrorMessage(getMessage('Attachment is mandatory'));
        return false;
    }
}

Harsha34_1-1730198355776.png

 

Thanks

 

1 ACCEPTED SOLUTION

Ensure the script I've provided you with is in an onsubmit catalog client script with the UI Type of 'desktop'. Delete your other script(s) you've created as they're not needed. Then use the checkbox function I mentioned previously to control the mandatory attachment requirement in the portal.

 

TL;DR - The script is making attachments mandatory in the glideapp backend view, the OOB functionality of the "Mandatory attachments" checkbox on the catalog item is controlling the portal/mobile view.

View solution in original post

9 REPLIES 9

Ensure the script I've provided you with is in an onsubmit catalog client script with the UI Type of 'desktop'. Delete your other script(s) you've created as they're not needed. Then use the checkbox function I mentioned previously to control the mandatory attachment requirement in the portal.

 

TL;DR - The script is making attachments mandatory in the glideapp backend view, the OOB functionality of the "Mandatory attachments" checkbox on the catalog item is controlling the portal/mobile view.

Aniket Chavan
Tera Sage
Tera Sage

Hello @Harsha34 ,

I just wanted to confirm that the client script is working fine on the Service Portal, right? If it is, then it's normal for the catalog item view (or Try It view) to not reflect all the customizations we made with client scripts or UI policies. That view has some limitations.

Since it’s working well on the Service Portal and ESC, you don’t need to worry too much about that view.

Let me know if you have any other questions!

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket

Hi Aniket,

 

Yes it is working fine on service portal. But the client wants that it should run on that view as well. Please let me know if you have any suggestion.

Hello @Harsha34 

 

I understand the client's request, but I want to point out that the Try It view is primarily intended for admins or catalog owners to quickly test functionalities and see changes. Generally, users will interact with the Service Portal or the ESC, as those are the primary interfaces.

In my opinion, you can inform the clients about the limitations of that view. It’s not designed for actual submissions or comprehensive testing—those processes should occur in the portals.

Given that we can achieve the same requirement by simply checking a box to make attachments mandatory, it might not be necessary to implement a custom script for that view.

If you have any further questions or need assistance, feel free to reach out!

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket



Aniket Chavan
Tera Sage
Tera Sage

Hello @Harsha34 

I also noticed your script again, and it seems you've used DOM manipulation. While it works, it's generally not recommended as a best practice. Instead of adding custom logic to make attachments mandatory, you can easily set this requirement directly from the catalog item record.

In the Portal tab, there's an option to make attachments mandatory. Just check that box, and it will enforce the attachment requirement for that catalog item.

 

AniketChavan_3-1730200097993.png

 

 

If you have any further questions or need assistance, feel free to ask!

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket