Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

ITSM Workflow Question

sanjaybagri
Tera Contributor

Hello Team,

 

I have a requirement : 

I am submitting the request and there we have certain approval after the creating the change request from the Run Script activity of the workflow in that workflow i want to wait till change request state should  move to implement state and once Change moves to implement then calling API for Integration.

 

Most of the thing are working as expected but only wait for condition is not working. i tried many approaches: 

1. When ever wait for condition is triggering then executing first time and returning the new value but i want implement state value. 

2. Wait for WF Event : this activity i used eventQueue & gs.eventQueueScheduled, Created event in event registry and triggering the event by Business Rule , Same event name passed in activity . before and after eventQueue info is generating but not moving in next activity.

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

gs.info("BR 1 ");
    if (current.state.changesTo(-1)) { // Replace 3 with your "Implemented" state value
        var journalGR = new GlideRecord('sys_journal_field');
        journalGR.addQuery('element_id', current.sys_id);
        journalGR.addQuery('element', 'work_notes');
        journalGR.orderByDesc('sys_created_on'); // Get latest note first
        journalGR.query();

        while (journalGR.next()) {
            var note = journalGR.value.toString();
            gs.info("Work Note: " + note);

            var match = note.match(/RITM Reference:\s*([a-f0-9]{32})/);
            gs.info("BR 2 "+match);
			if (match && match[1]) {
                var ritmGR = new GlideRecord('sc_req_item');
                if (ritmGR.get(match[1])) {
                    gs.info("Firing event on RITM: " + ritmGR.number);
                    gs.eventQueueScheduled('change.implemented', ritmGR, ritmGR.sys_id, ritmGR.number);
		   gs.info("Firing event on RITM after " + ritmGR.sys_id);
                    } else {
                    gs.error("RITM not found for sys_id: " + match[1]);
                }
                break; // Stop after first match
            }
        }
    }
})(current, previous);

 

 

I need help on Wait for condition step. 

Workflow is created in RITM Table and I want wait for change request. 

Please let me know if you need any additional information. 

 

Thanks a lot in advance and your support will be appreciate. 

 

Thanks

Sanjay Bagri

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@sanjaybagri 

Since workflow is on RITM and you want to create CHG and wait till CHG moves to Implement State, The wait logic won't work directly.

See this workaround which I shared -> you need BR on CHG table when State Moves to Implement which broadcasts the Workflow to proceed.

You need RITM stored on CHG then only you know which workflow to broadcast the message

I shared solution 5 years ago, see that and enhance

Approval Wait for Condition Stuck and will not move forward 

AnkurBawiskar_0-1759297186418.png

 

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

View solution in original post

5 REPLIES 5

Swapna Abburi
Mega Sage
Mega Sage

Hi @sanjaybagri 

When the BR is executed, can you see if event is created in Event log table? also, try replacing "gs.eventQueueScheduled" with "gs.eventQueue" method as you are not using any future date for event trigger.

 

SwapnaAbburi_0-1759259479644.png

 

Thank you @Swapna Abburi ,

 

I used evnetQueue and unable to get the solution. Event is triggered 

 

issue.png

@sanjaybagri 

if event is triggered in log and if the same event is used in workflow, then it should resume the workflow. Please share screenshot of the workflow activities.

Ankur Bawiskar
Tera Patron
Tera Patron

@sanjaybagri 

Since workflow is on RITM and you want to create CHG and wait till CHG moves to Implement State, The wait logic won't work directly.

See this workaround which I shared -> you need BR on CHG table when State Moves to Implement which broadcasts the Workflow to proceed.

You need RITM stored on CHG then only you know which workflow to broadcast the message

I shared solution 5 years ago, see that and enhance

Approval Wait for Condition Stuck and will not move forward 

AnkurBawiskar_0-1759297186418.png

 

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