Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Wait for Condition - Attachments

Andrew Wilmut1
Giga Contributor

Hello,
I've got a Wait for Condition on my workflow and I'm having some problems. I'm trying to check if my current sc_req_item has at least 1 attachment which will allow the workflow to continue. I'm querying the sys_attachment table looking for attachments as per below. However when I add an attachment to an item my workflow doesn't continue:

var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id','current.sys_id');
att.query();

//if records exist, there is at least 1 attachment
if (att.next()) {
answer = true;
}
else {
answer = false;
}

Can someone tell me what i'm doing wrong? I tried to wrap the query in a while statement as well but that, as you can imagine didn't work out.

Thanks
-Andrew

2 REPLIES 2

marcguy
ServiceNow Employee

I think you need to nudge the workflow that is running against the request item, this code below does this for me on change requests when a change task is updated to approved:

if(current.u_status > 1)
{
forceReqItemUpdate();
}

function forceReqItemUpdate() {
var wf = new Workflow();
var ri = new GlideRecord("change_request");
if (ri.get(current.parent)) {
wf.runFlows(ri, 'update');
}
}


Thanks for your response. Any reason why this wouldn't work:

Condition: current.short_description == 'Request Item'

var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id','current.sys_id');
att.query();

if (att.next()) {
forceReqItemAttachmentUpdate();
}

function forceReqItemAttachmentUpdate() {
var wf = new Workflow();
var ri = new GlideRecord("sc_req_item");
if (ri.get(current.sys_id)) {
wf.runFlows(ri, 'update');
}
}