Wait for Condition in Workflow Not Proceeding After Manager is Added

Aditya02
Tera Guru

Hi everyone,


I am working on a ServiceNow workflow where I need to check if a Line Manager exists for the requested user. If a manager is missing, the workflow should:


1️⃣ Change the state to "Transform"
2️⃣ Trigger a notification via an event
3️⃣ Wait until the manager is added
4️⃣ Once the manager is added, update the state to "In Progress"
5️⃣ Rollback to the first step to recheck for the Line Manager
6️⃣ If the manager now exists, proceed with the workflow

 

Issue Faced:

  • The workflow gets stuck at the "Wait for Condition" (WFC) step even after updating the manager field.
  • The state changes to "Transform" and triggers the notification correctly.
  • However, when the manager is added and the record is updated, the workflow does not move forward.
  • I'm using Rollback to Activity to return to the initial manager check, but it does not seem to re-evaluate properly.


Anyone, Help me out work on this. Here, I'm Giving the condition for WFC to check:
       

answer = true;
var LineManager = current.u_requested_for.manager.sys_id;

if (!LineManager) {
gs.log('No Line Manager found - Waiting for update');
answer = false;
}

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Aditya02 

the workflow wait will wait and listen for update on the current record to check the script and not on some other record

So you will have to use after update business rule on sys_user table

Condition: Manager Changes and Manager is not empty

Script:

check if this user is present in "u_requested_for" field of your table

If yes then get the active workflow context and propagate the update to that workflow so that it evaluates the condition and proceeds

Something like this in after update BR

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

    var wf = new Workflow();
    var rec = new GlideRecord("yourTable");
    rec.addQuery('u_requested_for', current.sys_id);
    rec.query();
    if (rec.next()) {
        wf.runFlows(ri, 'update');
    }

})(current, previous);

Also update your workflow wait script as this

answer = true;
var LineManager = current.u_requested_for.manager;
if (LineManager == '') {
gs.info('No Line Manager found - Waiting for update');
answer = false;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Aditya02
Tera Guru

Hi @Ankur Bawiskar ,

 

WIth this business rule can we continue the workflow, where it paused..? 

@Aditya02 

yes the workflow will continue as it got an update broadcast and it will evaluate the condition

Since condition became true it will proceed.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader