Approval not following cancelled output

kristenankeny
Tera Guru

I have a workflow that calls a few child workflows for approvals. In the approval workflow, I have added a condition to follow a "cancelled" output, but my workflow is not following it.

find_real_file.png

find_real_file.png

find_real_file.png

(I had previously had an if statement for counts.total == counts.cancelled, but that wasn't working, thus adding the counts.requested == 0).

Another workflow is running on the approvals table and it is successfully moving the approval to "cancelled", but the requested item workflow is failing to move forward along the cancelled path.

Approval controls workflow:

find_real_file.png

Example of failure:

        This shows that my approval is cancelled:

        find_real_file.png

        This shows that the requested item workflow is still pending approval:

        find_real_file.png

1 ACCEPTED SOLUTION

Hello Kristen, I am suspecting you are doing something outside the standard behavior and may be running into what's documented at Custom Transitions for the Approval - User Activity - ServiceNow Wiki      



The document says


"In the baseline system, ServiceNow provides a business rule called SNC - Run parent workflows (Approval) that triggers the workflow associated with the task of the current approval when the following conditions occur:  


current.state.changesTo('approved') || current.state.changesTo('rejected')   || current.operation() == 'delete'"

So, I think you need to change this BR and add an additional condition for cancelled.


View solution in original post

9 REPLIES 9

Geoffrey2
ServiceNow Employee
ServiceNow Employee

Try using log statements to see what the values of all of the counts are when the script executes.   That should tell you what's going on.



gs.log('total: ' + counts.total + '\napproved: ' + counts.approved + '\nrejected: ' + counts.rejected +


            '\nrequested: ' + counts.requested + '\nnot_requested: ' + counts.not_requested + '\nnot_required: ' + counts.not_required);



if (counts.approved > 0)


  answer = 'approved';


// etc


Thanks for the suggestion! I added this line, but it's not being triggered at all.


It's not appearing in the Log at all?


Either the Script is not getting executed, or it's failing because of some error.


Try a nice, safe, string only log statement at the start.   Like gs.log('Approval script is executing' ,'GS');


The second parameter sets the Source of the log statement. I normally use my initials.   It makes it much easier to find your statements in the log. Just search by Source == 'GS' (or whatever).


If that first line isn't appearing in the log, then the script isn't executing.



Do you have to check the Advanced checkbox for the Script to be executed?


I tried the simpler statement, but the approval step in the workflow isn't recognizing the update to the approval task, so it's not triggering at all. The approval step is set to wait for a condition based on script. The advanced checkbox pulls up a script box for scripting who receives the approval task. I don't understand why they would give you the option to set the state to cancelled, but not provide a way to exit the approval step when its cancelled.