- 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-13-2015 06:51 AM
Okay so that got me to be able to get it to pass yes. Now the problem though is I am looking for it to check for a "new" attachment from when it was submitted. So if they attach something when submitting then it just blows past that check because there is something there already.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 06:59 AM
The key here will be what would conditions quantify as 'new'.
If it's as simple as it was just added, you can filter the attachment query to only look for attachments created today, or last 15 mintues:
gr.addEncodedQuery('sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)');
gr.addEncodedQuery('sys_created_onONLast 15 minutes@javascript:gs.minutesAgoStart(15)@javascript:gs.minutesAgoEnd(0)');
Or maybe check against the time the item was created (if the other attachment was added at submit) .
so something like
gr.addQuery('sys_created_on','>',current.sys_created_on);
- 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
‎11-12-2018 12:10 AM
Hi,
I had a similar requirement. And this is working fine when this is attached through back-end. But issue is when an attachment is attached to the RITM via Service Portal, this script doesn't looks like working. The workflow just waits on the same if activity.
Have anyone faced this issue? Can anyone help me with it?