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

Kieran Anson
Kilo Patron

As your script isn't conditional, you can set the mandatory flag on the catalog item record

KieranAnson_0-1730198977464.png

 

Hi Kieran,

 

I tried but this is also not running on glideapp.servicecatalog_cat_item_view.

Thanks

I wasn't aware that it didn't apply to the backend.

You can create a new onSubmit client script with a UI type of 'Desktop' and in the script 

function onSubmit() {
  
  var attachmentCount = Number(getCurrentAttachmentNumber())
  if(attachmentCount == 0){
	g_form.addErrorMessage(getMessage('error_message_key'))
	return false;
  }
   
}

I tried this script. It is working on backend as well that is glideapp but the issue is I am getting error too 'There is a javascript browser code error'.

 

Please let me know how to resolve this.