Process Manager Instance Search Return Invalid Object

Discussions concerning general integration topics.

Moderator: Phil Barton

Post Reply
Posts: 33
Joined: Mon Jun 14, 2021 9:47 am

Process Manager Instance Search Return Invalid Object

Post by timothymeyer16 »

Good Morning.

I'm Attempting to create a program that cancels and restarts all process instances that are stuck.
The current built in system is malfunctioning.

In dev I can access the instances and cancel / restart them with the following code:

Code: Select all

 foreach (IProcessInstanceInfo instance in processMgr.Instances)
{ // Cancel // Restart}
However in prod, I run into memory issues because of the size of our system.

I tried taking the orders search method which works just fine:

Code: Select all

IOrderStore os = ss.GetService<IOrderStore>();
IOrderInfo search = os.Orders.Where(t => t.Number == orderNumber).First();
And applied it to instances (They are both IQuerable)

Code: Select all

IProcessManager processMgr = ss.GetService<IProcessManager>();
IProcessInstanceInfo idleInstances = processMgr.Instances.Where(t => t.Status.ToString() == "Idle").First();
But this returned an error:

Code: Select all

System.InvalidOperationException:[b] Operation is not valid due to the current state of the object.[/b]
   at SoftPro.ClientModel.Linq.ExpressionTreeHelpers.GetMemberExpressionFromBinaryExpression(BinaryExpression be)
   at SoftPro.ClientModel.Linq.CriteriaBuilder`2.WhereTranslator.VisitBinary(BinaryExpression b)
   at SoftPro.ClientModel.Linq.ExpressionVisitor.Visit(Expression exp)
   at SoftPro.ClientModel.Linq.CriteriaBuilder`2.WhereTranslator.Translate(CriteriaBuilder`2 builder, Expression expression)
   at SoftPro.ClientModel.Linq.CriteriaBuilder`2.TranslateWhereExpression(Expression whereExpression)
   at SoftPro.ClientModel.Linq.CriteriaBuilder`2.HandleWhereExpression(Expression expression)
   at SoftPro.ClientModel.Linq.CriteriaBuilder`2.Build(Expression& expression)
   at SoftPro.ClientModel.Linq.CriteriaQueryProvider`2.Execute(Expression expression, Boolean enumerable)
   at SoftPro.ClientModel.Linq.CriteriaQueryProvider`2.Execute[TResult](Expression expression)
   at SoftPro.ClientModel.Linq.CriteriaQuery`2.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Automation_Queue_Manager.IdleProcesses.GetIdleProcesses(SelectServer ss) in C:\_C# Projects\Automation Queue Manager\Automation Queue Manager\IdleProcesses.cs:line 26
If I change the value from "IProcessInstanceInfo" to "Var" it returns an un-useable object
( Also needed to remove the .First() as well)

Code: Select all

var idleInstances = processMgr.Instances.Where(t => t.Status.ToString() == "Idle");
// Returns:


Finally, I came across a post using a seach object which I also attempted, but without avail.

Code: Select all

var searchObjt = processMgr.NewProcessInstanceSearch(t => t.Status.ToString() == "Canceled");
var idleProcesses = processMgr.Instances.Search(searchObjt).ToList();
In the above example I can not "search" the instances as the example in the following example: ... ject#p4627

In summary, the same functionally for the same Iquerable Orders was not applicable on Process Instances.

Is there another way I can search / filter?
Or am I able to iterate over a certain number of instances when querying for all items?
Posts: 1221
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC

Re: Process Manager Instance Search Return Invalid Object

Post by BobRichards »

Here is my thought. When you get the "Instances", under the covers it is passing your search criteria (t => t.Status.ToString() == "Idle") to be interpreted by expression tree logic. We sometimes modify the parsing of it so it is faster or more efficient for Select. I think the logic is getting confused when you convert the Status to a string and then do string comparisons.

Try using this and not doing data type conversions. (An enum comparison is faster than a string compare anyway!)

Code: Select all

using  SoftPro.Select.Client.Automation;

IProcessManager processMgr = ss.GetService<IProcessManager>();
IProcessInstanceInfo idleInstances = processMgr.Instances.Where(t => t.Status == ProcessInstanceStatus.Idle).First();
Bob Richards, Senior Software Developer, SoftPro
Post Reply