Validate attachments on a record producer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2014 12:56 PM
I need to validate if the user has attached at least one document in a record producer and I'm trying to use the following function in the onSubmit Client Script but id doesn't work. I'm using the same function in the form itself and it works there.
The call to getUniqueValue() does not return anything. Does anybody knows what applies in this case?
function validateAttachments() { var sid = g_form.getUniqueValue(); var gr = new GlideRecord('sys_attachment'); alert(sid); return gr.get('table_sys_id', sid); }
Regards,
/Amado Sierra
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2014 02:23 PM
Hi Amado,
You can get the sys_id of the record producer using gel('sysparm_id').value.
Regards,
Solutioner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2014 08:58 AM
Thanks everybody for your help. I have compiled the couple of functions that worked for my purpose, based on the proposed solutions.
Here is the function I ended up using:
function validateAttachments() {
var sid = gel('sysparm_item_guid').value;
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', sid);
if (gr.next())
return true;
return false;
}
And here's an alternative solution that works, without retrieving the record producer's id:
function validateAttachments() {
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('You must attach at least 1 file before submitting this request.');
return false;
}
return true;
}