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

kristenankeny
Tera Guru

I have still not found an answer to this. I attempted updating an existing business rule (SNC - Run parent workflows), adding the state as an option on requested items, but no luck. The workflow "wait for condition" is still failing to trigger, despite my UI action updating the record to the appropriate state.


Hi Kristen,



In your UI action after current.update can you try adding current.setWorkflow(true) to see if that helps pick up the running of business rules which will trigger the workflow.


Hi Venkat,



I tried that and it still isn't proceeding. The UI Action runs, it updates the record, but the wait for condition is still sitting and waiting. I even tried changing what it waits for from the state to the approval field and the UI action updates the approval field to "requested", but this still is not getting the workflow to move forward.


Hi Kristen,




1. I am sure you would have checked these but still wanted to verify whether the table the workflow is running on is the same as the one you are updating the UI action for and the business rule is running as well. i.e. Required Item


2. Also can you add a gs.log in the wait for condition



function ifScript(){  


  gs.log(current.state);


  if(current.state == 9){  


  return true;  


  }  


  else{  


  return false;  


  }  


}  




3. Also, can you paste the code you are using to resume your workflow here please.




Thanks


Hi Venkat,



I have done logging and the script to restart the workflow is the one you provided. Though I'm confused as that would be needed since I didn't have to add it for my other custom table. The logging gives me nothing, the workflow doesn't do anything despite still running.