- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2014 02:59 PM
Is there a way to check for attachments in the current form and making attachment mandatory if a field is checked ?
Solved! Go to Solution.
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2014 10:59 AM
Hi Ankit Lohani
Try the below script,If you are looking for mandatory attachments on catalog item.
function onSubmit() {
var cat_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2014 03:15 PM
If you are talking about ServiceCatalog form then,
- /*
- For the Client Script on the request item/Record Producer
- Name: Mandatory Attachments
- Applies to: A Catalog Item
- Type: OnSubmit
- */
- function onSubmit() {
- if (g_form.getValue('u_order_guide') == 'Yes') {
- var ord_id = gel('sysparm_cart_edit').value;
- var gr = new GlideRecord("sys_attachment");
- gr.addQuery("table_name", "sc_cart_item");
- gr.addQuery("table_sys_id", ord_id);
- gr.query();
- if (!gr.next()) {
- alert("You must attach a file to submit.");
- return false;
- }
- }
- else if (g_form.getValue('u_order_guide') == 'No') {
- var cat_id = gel('sysparm_item_guid').value;
- var gr = new GlideRecord("sys_attachment");
- gr.addQuery("table_name", "sc_cart_item");
- gr.addQuery("table_sys_id", cat_id);
- gr.query();
- if (!gr.next()) {
- alert("You must attach a file to submit.");
- return false;
- }
- }
- }
If you are talking about incident, change or some table then,
- var sys_id = gel('sys_uniqueValue').value;
- var attachment = new GlideRecord('sys_attachment');
- attachment.addQuery('table_name','incident');
- attachment.addQuery('table_sys_id',sys_id);
- attachment.query();
- if (attachment.next()) {
- alert ('There is an attachment.');
- }
- else {
- alert ('There is no attachment.');
- }
Please dont use any Business Rule, you will be wasting a Server - Client transaction.
Now that using the above snippet you can know if an Attachment is attached or not. If that field you are talking is checked, let the onsubmit run, if not skip it.
Both the snippets aren't written by me. We have something similar but not exactly similar. The second one is written by Geoff Cox and the first I don't know who.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2014 08:30 AM
Hey Abhiram, I used this script in the catalog item,
function onSubmit() {
if (g_scratchpad.hasAttachments)
{}
else
{alert('You need to attach a SQL script to this form. ' );}
}
and that is not doing anything.
What is going on ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2014 08:33 AM
I am not sure why you are using this on Catalog Item, I mean did you see this somewhere?
Also can you try using the script I pasted above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2014 08:38 AM
Where do you think this should be used instead of the catalog item ?