The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Workflow: Wait-for-condition still stuck after timeout expires

sanasayyad
Tera Contributor

Requirement: After approver Rejects, I want the workflow to wait up to 7 days for any journal comments on that RITM. If a comment appears within 7 days → immediately go back to Approval. If no comment in 7 days → mark ticket as Closed Incomplete.

 

Current behaviour: For testing I set Wait Timeout = 0d 0h 1m. After 1 minute the workflow stays stuck in the Wait activity.

Notes: I have not yet saved the rejection time to workflow.scratchpad. I will add an advanced query on the sys_journal_field  table later to check for entries created after the rejection time.

 

 

//-----------------------------------Wait for Condition Script ------------

var found = false;
var a = current.sys_id;
gs.info("sananan" + a);
var jr = new GlideRecord('sys_journal_field');
jr.addQuery('element_id', a);
jr.addQuery('element', 'comments');
jr.query();
gs.info("the row count is" + jr.getRowCount());
while (jr.next()) {
    gs.info("going inside the wait for condition ");
    if ((jr.value + '').trim().length > 0) {
        found = true;
        break;
    }
}

answer = found ? true : false;





//------------------------If Script - Check if Comments came or not 
(function() {
    // Helper:
    function hasRecentComment() {
       
        var jr = new GlideRecord('sys_journal_field');
        jr.addQuery('element_id', current.sys_id);
        jr.addQuery('element','comments');
        jr.query();
        gs.info("the row count for if is"+jr.getRowCount());
        while (jr.next()) {
            var val = (jr.getValue('value') || '') + '';
            if (val.trim().length > 0) {
                gs.info('WF: If-check found journal by ' + jr.getValue('sys_created_by') + ' at ' + jr.getValue('sys_created_on'));
                return true;
            }
        }
        return false;
    }
 
    answer = hasRecentComment() ? 'yes' : 'no';
})();

 

 

For reference, I am attaching the screenshot as well, so that you can get an idea of how I have configured the timeout in wait for condition 

 

Issue:

When I post a comment within 1 minute (i.e., when the condition evaluates to true), the flow works properly and goes back to approval. However, when no comment is posted, it gets stuck. After 1 minute, it should proceed as the timeout is already configured.

 

 

 

 

 

1 REPLY 1

sanasayyad
Tera Contributor

kindly find the attached workflow forget to attach Workflow.png