- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 06:04 AM - edited ‎04-29-2025 06:13 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 07:33 AM
Hello @Sandeep Goudar ,
You can create a Business Rule (or a Flow) on the sc_req_item table, as shown below:
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 07:35 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 06:27 AM
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
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 07:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 07:00 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 07:11 AM
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.");
}