Question

How to get ActivityInstanceId of a SmartObject step in "Wait for External System" state using API?

  • 28 January 2024
  • 3 replies
  • 28 views

Badge +2

I have a workflow that pauses for external system work using the “Wait for External System” (Synchronous) option on a SmartObject step. When it’s in this state, it does NOT show up when I call GetWorklistItems using the Management API (because it’s not in a worklist). If I dig through the database (we are running on-premise) I can see the current activity instance in the log table, but I’d prefer to get this information from the API and ot via SQL Query so that we can one day move to the cloud based version. 

 

Anyone know how to find this using the API? Obviously the Workspace front-end is able to query this information via some API, since it shows what the current activity is and how long it’s been there.

Please note that I do NOT want the list of Activities, I want the Activity INSTANCE of the current step of of a given Process Instance when it’s in the waiting state. 

Thanks!


3 replies

Userlevel 2
Badge +4

 Hi Chris

I believe what you want to do is communicate the tasks serial number with the external system.

I do this by using the SmartObject method called when initiating the wait.

In my example I will use SQL SmartObject create method for ease, but this could be a webservice call to the external system or any SmartObject Method.

I will then use the Serial Number from the external system to complete the task.

 

External System Contacted through SmartObject

 

In the workflow pass the serial number of the step to the external system through the SmartObject Method.

Workflow performing wait and communicating Serial Number through a SmartObject Method.

So when the workflow runs the external system receives the serial number of the step. as shown below.

External system now has Serial Number for the task.

I can complete the workflow from an external system through K2 APIs

Workflow Rest Service 

Finish the task through rest service.

Or you could do it through the .net API

See the below link.

https://help.nintex.com/en-US/k2five/userguide/5.6/Content/How-Tos/WaitExternal/Wait-External-System.htm

Hope this helps

Badge +2

I believe what you want to do is communicate the tasks serial number with the external system

 

I appreciate the detailed response, but I also know that it’s cut and pasted from the documentation or other “how-to” articles that I have already read. That’s not what I want to do. What I want to do it be able to get the ID for the ActInstDestId number from the system by using the API.

My SmartObject does nothing - it doesn’t actually call any external service or anything else. The Smart Object step is just there to put the workflow in a wait-state as we used to be able to do with “Server Events” in the old K2 designer. I don’t want to have to store the serial number somewhere in the external system as I wait for the action to happen there that should release the wait on the workflow (could happen days or weeks later). To be honest, I don’t even really need the serial number, as I can just do an API call to move the workflow to the next step rather than completing the task, but there’s two problems with that; the first is that I want to make sure the process is actually at the Async SmartObject step before I move it on, and the second problem is that calling ServerEvent.Finish is nicer / cleaner than moving the to a different task via the API.  If there’s no way to call the “Get” functions of the management or client API and see that the current activity is at the SmartObject async (Server Event) step then I can’t be sure it’s where I think it is (I suppose  could assume that if the process is running and I can’t get a worklist item, then it’s at a Server Event - but that’s cheesy) 

For now I am simply querying the database, and that’s working but I’d prefer to move away from that. 

Thanks,
Chris

Userlevel 2
Badge +4

Hi Chris

With “Server Event” no longer possible, the “wait for external system” and storing the Serial Number is, supposed to replace the Server Event “Async = true”

The serial Number is a combination of ProcessInstID and ActInstDestID, xxxx_yy, where xxxx is the ProcessInstID and yy is the ActInstDestID.  Alternatively query the DB for is should be OK, as long as you make no changes to it.

Your reply mentions two problems

1 “I want to be sure that the solution is at the desired step”

Workflows, Activities/Steps and Events/Tasks (Old Designer/New Designer terminology) have one of the following statuses.

Running - the server is actively executing this Workflow.

Error - and exception has been thrown, the workflow is in error.

Complete - No more work

Active - Currently awaiting external action.

 

The below SmartObject call should retrieve a list you could use.

Event Instance

This approach has a problem.  It requires that your Activity Display Name is unique across all solutions, unless you also filter on the Process instance ID.  

2 “and the second problem is that calling ServerEvent.Finish is nicer / cleaner than moving the to a different task via the API”

Reconsidering storing SerialNumber and actioning either through REST or .net API.  both these options require the SerialNumber in anycase.  You could even expose this functionality as a SmartObject through RESTful broker or assembly broker.

If the task is nolonger active the API will throw an exception.

Hope this helps

Reply