Wait For Condition Not Working

Tylerjknapp
Tera Contributor

I have a variable that is hidden on the RITM but is visible and mandatory on the SCTASK. The user selects yes or no and if the user selects yes the workflow should move on from the wait for condition. After doing some research I realized that the workflow is running on the sc_req_item table and the variable update is on the sc_task table. So I found a business rule to force an update for the workflow to continue which is below 

 

(function executeRule(current, previous /*null when async*/ ) {
// force update of RITM when catalog task is closed.  
    var grRitm = new GlideRecord('sc_req_item');
    grRitm.get('sys_id', current.request_item);
    grRitm.setForceUpdate(true);
    grRitm.update();

})(current, previous);

 then in the wait for condition activity I put the following code - 

answer = ifScript();

function ifScript() {
    var gr = new GlideRecord('sc_task');
    gr.addQuery('request_item', current.sys_id);
    gr.addQuery('short_description', 'CONTAINS', 'Order New Services');
    gr.query();

    if (gr.next()) {
        if (gr.getValue('need_to_upload_the_service_agreement_or_contract') == 'Yes') {
            workflow.info('MACD Answer=True');
            answer = true;
            return answer;
        } else {
            workflow.info('MACD Answer=False');
            answer = false;
            return answer;
        }
    }
    return answer;
}

I've tried just doing a simple if statement, like below 

if(current.variables.need_to_upload_the_service_agreement_or_contract == 'Yes') {
answer=true; 
}else{
answer=false; 
}

 and that isn't working as well. What am I missing here? 

9 REPLIES 9

Hmmm.  Have you confirmed this variable remains populated after the task, so on the RITM you see that it is not blank?  Does another/manual RITM update and/or the Nudge button on the Workflow Context make it continue?  There's not much to these activities, and the condition builder doesn't leave much room for error, so I can't think what else would be confusing it.

 

Unrelated, but there are a couple of things I see here that may cause you trouble later.  On Join activities I always connect the Complete and Incomplete conditions to the same next activity.  This is supposed to differentiate if any of the previous activities closed in a different state, but I've seen it take the incomplete path when I wasn't expecting that, so you should always have a next step for every possible result.  Similar with the If right before this troublesome Wait for - there's not a No condition and path.  If it is possible for the result to be No, then the workflow will get stuck there forever without a next step.  If it is not possible for the result to be No, then it's not really an if statement.

Hi Brad, correct, that was one of the first things I checked. On the RITM the variable was displaying the default value of "None". On the SCTASK it was also displaying "None". Upon changing it to "Yes" + Save & Exit, it was updated on the RITM and SCTASK. I will see if the complete/incomplete is possibly causing this. Normally I do as you said connect complete and incomplete to the same end activity. I did not originally design this workflow, so I try not to touch stuff I don't have to as there may be a reason I'm unaware of that it was originally designed like that. Regarding the If statement, the only time that that would equate to no is if the RITM State was in one of the closed states. As that is what that if statement is checking. 

 

I may try backing out this update set and just starting over. The variable I'm trying to check is a Yes/No variable with "None" as the default. There is a catalog client script that make it is visible and mandatory on the specific SCTASK it needs to be on and hidden on all other. I unchecked the box to apply this catalog client script to RITMs to confirm if it was reflecting on there when the value was changed. Not sure if you know about any bugs with Yes/No variables and Wait for Conditions, figured it wouldn't hurt to tell you the type of variable. 

So the nudge button did work. It generated the task after that. I'm just unsure of why it's getting stuck at that activity. 

I don't typically use Catalog Tasks that don't wait for completion, so I don't know if it's related to that, but maybe that's why the Business Rule you mentioned to force an RITM update was conceived.  If it's sitting on the Wait for when this variable is updated/task is closed, that might have the same effect as the Nudge.

Tylerjknapp
Tera Contributor

Thanks Brad, I will try that now!