- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 12:42 PM
I am trying to create a check to see if an attachment was added to the Requested Item in the workflow. Though for some reason I am having a problem with getting the check to work correctly.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 10:27 AM
So what the requirement was is to check for an attachment at a certain stage. Once on that stage the if check would check to see if there was an attachment added since it has been in that stage. The same could be used for various events but stage was the easiest for us. Here is what works and is validated by me. Thanks everyone for the help too.
function ifScript() {
var gr = new GlideRecord('sys_audit');
gr.addQuery('document_key',current.sys_id);
gr.addQuery('field_name','stage');
gr.addQuery('new_value','reaudit4day');
gr.query();
if(gr.next()) {
var grr = new GlideRecord('sys_attachment');
grr.addQuery('table_sys_id',current.sys_id);
grr.addQuery('sys_created_on',">", gr.sys_created_on);
grr.query();
while(grr.next()) {
return 'yes';
}
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 12:51 PM
How are you trying to do it?
I would normally query the sys_attachment table filtering on table sys id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 02:14 PM
Mike,
You can use the following GlideRecord to check for it :
http://wiki.servicenow.com/index.php?title=GlideRecord#hasAttachments&gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 06:08 AM
So what I have now is:
answer = ifScript();
//
function ifScript() {
var gr = new GlideRecord('sys_attachment');
gr.addQuery("sc_request", "sc_req_item");
gr.addQuery('sys_id', current.request_item);
gr.query();
if (gr.next){
if(gr.hasAttachments()){
return 'yes';
}
}
else if (gr.next){
if(!gr.hasAttachments()){
return 'no';
}
}
}
Though every time it comes up with no as the answer regardless of how many attachments are on the requested item. Also looking for a way for it to tell if there is a new one since the last check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 06:16 AM
Your query filter doesn't look correct.
Also, if you are querying this table, just the fact that it has a row means there is an attachment.
Try this:
answer = ifScript();
//
function ifScript() {
var gr = new GlideRecord('sys_attachment');
gr.addQuery("table_name", "sc_req_item");
gr.addQuery('table_sys_id',current);
gr.query();
if (gr.next)
return 'yes';
else
return 'no';
}