On Submit Client Script not working on Catalog Mandatory Attachment

Sandeep Goudar
Tera Contributor

Hello,

I have written an OnSubmit Catalog Client Script to print an info message. In the catalog, I have made the attachment mandatory. However, whenever I try to submit without attaching a file, the info message from the script gets triggered. This is not the intended behavior; the OnSubmit script should only trigger upon actual submission.

If anyone has faced a similar issue or has a solution, please help me out.

 

 

2 ACCEPTED SOLUTIONS

Hello @Sandeep Goudar ,

 

You can create a Business Rule (or a Flow) on the sc_req_item table, as shown below:

 

RobertH_0-1745937169431.png

 

Regards,

Robert

View solution in original post

@Sandeep Goudar 

you can write after insert business rule on sc_req_item with condition as this to show the message after user submits request

current.cat_item.name == 'Your Item Name Here'

Script:

   gs.addInfoMessage("Your request to deactivate the user has been successfully submitted.");

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Sandeep Goudar 

if your requirement is to make attachment mandatory during submission then simply select this checkbox for portal

Unless user adds file they can't submit catalog item from portal, no scripting required

AnkurBawiskar_0-1745933210874.png

 

Share your script here and screenshot of client script configuration

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I have added the code below, I am not able to attach the images

 

Robert H
Mega Sage

Hello @Sandeep Goudar ,

 

This is the expected behavior. An onSubmit script runs before the form actually gets submitted and records are created. Its purpose is mainly to validate the user input.

Now if you also have enabled the Mandatory attachment checkbox on your Catalog Item then this is an additional validation that runs on submit. So if you try to submit the request without an attachment you get both the missing attachment error (only in portal UI) and the message from your onSubmit script.

 

Regards,

Robert

Thanks, @Robert H and @Ankur Bawiskar  How can we overcome this issue? Is there a possible solution? The message from my onsubmit script should only appear after the record is submitted, rather than displaying the error and message simultaneously.

Here is my simple OnSubmit client script

function onSubmit() {
   //Type appropriate comment here, and begin script below
   g_form.addInfoMessage("Your request to deactivate the user has been successfully submitted.");
   
}