Wait for Condition not triggering - Custom table

kristenankeny
Tera Guru

I have extended both the request and the requested item tables to create two new tables: position and required item, respectively. This is to allow people to define what catalog items are required for new hires so we can automatically script creation of the requested items upon submission of the onboarding form. In the process, I have approvals on both the position and the required item and we need to allow "rework" of the information if rejected. This is functioning without any issues on the position, but failing on my required items and I cannot figure out why. I'll try to provide as much info as possible:

On the approval table, I added a field u_approval_type that captures if the rejection is complete or they just want the information updated.

find_real_file.png

If the approver decides the required item needs update, the required item loops back to "draft" state and becomes editable.

find_real_file.png

Once ready for approval again, the user clicks a UI Action called "Request approval" that runs this script:

action.setRedirectURL(current);

current.state=9;

current.update();

gs.include('ActionUtils');

var au = new ActionUtils();

au.postInsert(current);

This is appropriately setting the state back to Required item review (or Position review on the position):

find_real_file.png

but you can see that the Approval is not going back to "requested" as it should on required item. This is what the running workflow looks like:

find_real_file.png

And this is what the wait condition is running:

answer = ifScript();

function ifScript(){

  if(current.state == 9){

  return true;

  }

  else{

  return false;

  }

}

It was originally not using a function, but that also didn't work. (It was just the if/else with "answer = true;" or "answer = false;"). I added logging at one point and I get logs when the required item doesn't meet the condition, but upon clicking the UI action and the update of the record to "Required item review", the condition never triggers again. I'm baffled as to why.

1 ACCEPTED SOLUTION

I finally was able to get it to move forward. I made an adjustment to the script you suggested so that it matched the "nudge" ui action on workflow context:



(function executeRule(current, previous /*null when async*/) {



  resumeWorkflow();




  function resumeWorkflow() {


  gs.info('resumeWorkflow called on required item');


  var wf = new Workflow().getRunningFlows(current);


  while(wf.next()) {


  gs.info('resumeWorkflow found the workflow');


  new Workflow().broadcastEvent(wf.sys_id, 'update');


  }


  }



})(current, previous);


View solution in original post

11 REPLIES 11

venkatiyer1
Giga Guru

Hi Kristen,



The wait for condition needs a workflow update option so that it could resume. You can do that by creating a business rule on the table the workflow is attached to once the required item has changed the state.



resumeWorkflow();




function resumeWorkflow() {


    var wf = new Workflow().getRunningFlows(current);


    while(wf.next()) {        


          new Workflow().broadcastEvent(wf.sys_id, 'resume');


    }


}


Hi Venkat,



I tried this and added logging to it. It logged that it triggered and found the workflow, but my workflow still is waiting and not moving forward.


Hi Kristen,




Thanks for your reply. Can you elaborate a bit more on actionutils within your UI action and can you comment out the actionUtils piece and give it a try? I dont see any other reason why it wont get triggered.


Hi Venkat,



I don't think it's the actionUtils, that's just controlling the redirect and I'm using it on an almost identical UI Action on the other custom table I created and it's working to re-trigger the workflow without issue. Is it possible that the issue is that the state value I'm setting it to is a value only exists for my extension table and not the sc_req_item table, and the workflow is running on the sc_req_item table? I'm going to try changing this to see if that resolves the issue.