Get workItem ID's of all queued waiting activities

Hi All.

I've a use case where we need to cancel all the queued activities after the current activity processing is completed. We have interaction manager method CancelActivity which accepts WorkItemID as input parameter which works fine cancelling the current activity.

Is there any way we can get all the WorkItem ID's which are waiting in the queue and cancel them after the current activity process completion i.e. on event ActivityCompleted.

As a work around I'm currently cancelling the next 3 activities incrementing the workItemID of current running activity. But eventually there could be less/more than 3 activities in the queue.

Appreciate your suggestions/comments.




Keep up to date on this post and subscribe to comments

November 15, 2019 - 12:37pm

I do not know of a way to view the queue, but the way I have handled this is to create a LookupTable with a single column. When you call the StartActivity method of an activity, the result is the WorkItemID. You can store that in the lookup table. When you need to cancel the activities, you can simply iterate through the LookupTable and cancel each one individually (and then clearing the table afterwards).

Another way is to use an Interaction. If you close an interaction, there's an option to cancel all activities for that interaction. This would mean you'd need to start each activity with an interaction key though, so it might mean some re-factoring.

November 15, 2019 - 2:43pm
Response to tsasnett

HI Thomas,

Thanks for your response.

Following the first approach of maintaining a lookup table storing WorkItemID at the start of activity. While the current activity is being executed I can see all the next triggered activities being added to the bottom of the queue in the logs(example below) as it is waiting for the present activity to complete. but these activities are not getting stored in the lookup as they are yet to be pulled and executed so not in lookup. And checking on the table keys at the end of current activity completion gets me only the WorkItemId that was being executed. Is there something I'm missing or misunderstood.

Ex - Activity added to bottom of queue. WorkItemId: '2' interactionKey: '1' activityName: 'ProcessEOC'

Activity added to bottom of queue. WorkItemId: '3' interactionKey: '' activityName: 'ProcessRDA'

Appreciate your help here.



November 15, 2019 - 3:24pm

You would need to;

  1. Create a new lookup table.
  2. Add a column to it.
  3. Modify your automations wherever you are calling StartActivity to call the AddRecord method of the LookupTable.
    1. You would pass the Result from StartActivity to the AddRecord method of the lookup table.

Did you do that? None of that would happen automatically, you'd have to code for it.

November 15, 2019 - 3:51pm
Response to tsasnett

Hi Thomas,

Yes, All of the steps mentioned were done.

Some more insight on the process. I've a main activity which gets triggered for all activities validating the needed values for that particular process activity to be triggered and on completion of the main activity it will trigger the respective process activity according to the trigger name.

I've added the lookup table Addrecord method for all the activities that will add the WorkID;s to the lookup table. Tested this approach, While the current process activity was in execution couple more activities were added to bottom of the queue and on the current process activity completion the lookup table returned 2 records(workID's) i.e. main and process activities but not the other 2 activities which were waiting in the queue. Appreciate your help.



November 18, 2019 - 8:42am
Response to RohitPrakashC5206

I didn't really understand your response. To remove an activity from the queue, you simply call the CancelActivity method from the InteractionManager. You pass it the activity ID, which you receive whenever you start an activity. If you record these and then call the CancelActivity method for all of the IDs that you have recorded, then your queue will be empty.

November 25, 2019 - 9:38am

Currently it is fetching the activity workID's which are getting captured on each StartActivity method which is eventually getting triggered from Pega RM. And somehow the one's which are getting added to the queue are not part of the lookup table which is being maintained to store all these ID's, For time being we are implementing the approach to cancel next 3 activities by incrementing the last captured ID stored in the table.