- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2022 05:03 AM
Hi,
I have a query regarding attachments its always having a confusion with attachments. While submitting form we need to check if user has attached 2 attachments we should allow to submit else abort the action.
How can we achieve this requirement and what is the best practice in Servicenow? I even referred DOM manipulation and some sort of leads whereas using GlideRecord in onSubmit which is not preferrable.
Please help me to get this requirement.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2022 05:10 AM
Hi,
Take a look at blogs.
Verify Mandatory Attachments Count on Catalog Item
Service Portal Catalog Items: Hide Attachment / Mandatory Attachment [Madrid]
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2022 05:10 AM
Hello Lakshmi,
Technically you should try to avoid validations in onSubmit which requires an dependency from the server side script. Because by the time you try to fetch data from SN, your form will be already submitted.
The best approach is to do this in before insert BR on sc_req_item table and add the script
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id",current.sys_id.toString());
gr.query();
if(gr.getRowCount()<2) {
gs.addErrorMessage("please upload atleast 2 attachments");
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2022 05:45 AM
Hi ,
As You recommended I made changes in PDI instance and still I can able to submit the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2022 05:46 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2022 01:12 AM
Hi,
I assume request is submitted, but not the ritm.
If you want to restrict this on form itself, then instead of using default attachments, tryto use a custom field of type attachment and make it mandatory. and then on load make g_form.submitted as false so that the form is not submitted and then write your logic in on Sumbit and all good make submitted attribute as true and submit the from through script using g_form.submit();
Mark the comment as a correct answer and also helpful if this helped to solve the problem.
Mark the comment as a correct answer and also helpful if this helped to solve the problem.