- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2015 10:45 AM
Hi everyone,
I've seen a lot of script for checking attachments, but I can't seem to track one down that is conditional on whether or not a catalog variable is blank. I have this portion already:
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("Attach manager and/or site manager's approval email for cart movement");
return false;
}
}
I know that I need to add something to this that checks one variable and if it returns "null" to make it mandatory for attachments. Any help would be appreciated.
Thank you,
Amandah
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2015 11:13 AM
Amandah,
If i'm understanding your question, you'll probably just need to add an additional if condition at the top of the script, something like...(i haven't tested this, fair warning)
function onSubmit()
{
if (g_form.getValue('FIELD_NAME') == '') { //replace with whatever your catalog variable name is
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("Attach manager and/or site manager's approval email for cart movement");
return false;
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2015 10:52 AM
Hello Amandah,
Please check section 8.16 for more info.
http://wiki.servicenow.com/index.php?title=GlideRecord#hasAttachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2015 10:56 AM
Hi Pradeep,
Thanks for the link, but I'm already aware of how to check the record for attachments. What I need is to find out how to add a condition to it to only alert to add an attachment if one of the catalog variables is blank. That code doesn't look to do any of that.
Thank you,
Amandah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2015 11:13 AM
Amandah,
If i'm understanding your question, you'll probably just need to add an additional if condition at the top of the script, something like...(i haven't tested this, fair warning)
function onSubmit()
{
if (g_form.getValue('FIELD_NAME') == '') { //replace with whatever your catalog variable name is
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("Attach manager and/or site manager's approval email for cart movement");
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2015 12:19 PM
Thank you! This is what I was looking for. I'll try it out.