Question

System.NotSupportedException: EntityCollection Setting "Collection of Objects (EntityCollection)" from a script task inside a BP

Hi,

 

I'm trying to retrieve a collection using EntitySchemaQuery but when try to assign it to a Parameter i get the following error:

System.NotSupportedException: EntityCollection
   at Terrasoft.Core.Process.FlowEngineStateService.InternalSetValue[T](Guid processUId, String parameterPath, T value)
   at Terrasoft.Core.Process.FlowEngineStateService.Terrasoft.Core.Process.IInternalProcessParameterStore.InternalSetParameterValue[T](Guid processUId, String parameterPath, T value)
   at Terrasoft.Core.Process.ProcessInstanceParameterStore.SetParameterValue[TValue](String parameterPath, TValue value)
   at Terrasoft.Core.Process.ProcessInstanceParameterStore.SetParameterValue[TValue](ProcessSchemaParameter parameter, Guid schemaElementUId, TValue value)
   at Terrasoft.Core.Process.ProcessModel.SetParameterValue[T](FoundParameterData result, T value)
   at Terrasoft.Core.Process.ProcessModel.TrySetValue[T](ProcessSchema processSchema, String propertyPath, T value)
   at Terrasoft.Core.Process.ProcessModel.Set[T](String propertyPath, T value)
   at Terrasoft.Core.Process.UsrGetLeadsBySalesCompanyMethodsWrapper.ScriptTask1Execute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessScriptTask.InternalExecute(ProcessExecutingContext context)
   at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

Example code:

var salesCompanyId = Get<Guid>("InSalesCompany");
 
// Creating a query instance with the "Lead" root schema.
var esqLead = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "Lead");
esqLead.AddColumn("UsrSalesCompany");
esqLead.AddColumn("CreatedOn");
esqLead.AddColumn("UsrLeadPriority");
esqLead.AddColumn("Id");
esqLead.Filters.Add(esqLead.CreateFilterWithParameters(FilterComparisonType.Equal, "UsrSalesCompany.Id", salesCompanyId));
 
// Filters in the query filter collection will be combined with the logical OR operator.
esqLead.Filters.LogicalOperation = LogicalOperationStrict.Or;
 
 
var entities = Get<ICompositeObjectList<ICompositeObject>>("ReadActiveOverrides.ResultCompositeObjectList");
foreach(var entity in entities) {
 
    Guid value;
    var fromSalesCompanyId = entity.TryGetValue<Guid>("UsrFromSalesCompany", out value) ? value : Guid.Empty;
    var toSalesCompanyId = entity.TryGetValue<Guid>("UsrToSalesCompany", out value) ? value : Guid.Empty;
 
    if(fromSalesCompanyId == Guid.Empty){
        throw new Exception($"fromSalesCompanyId it is an empty guid {entity.ToString()}");
    }
 
    if(toSalesCompanyId == Guid.Empty){
        throw new Exception($"toSalesCompanyId it is an empty guid {entity.ToString()}");
    }
 
	esqLead.Filters.Add(esqLead.CreateFilterWithParameters(FilterComparisonType.Equal, "UsrSalesCompany.Id", fromSalesCompanyId));
}
 
/*
Select selectEsq = esqLead.GetSelectQuery(UserConnection);
throw new Exception(selectEsq.GetSqlText());
*/
 
var res = esqLead.GetEntityCollection(UserConnection);
 
Set("OutLeads", res);

Paremeter OutLeads is a Collection of Objects (EntityCollection)

Any help is appreciated

 

Like

6 comments

Theoretically, you can debug the business process and find the reason. Please check the "Server code debugging" article in the academy.bpmonline.com. However, I recommend you to investigate the situation one step forward. There is no way to operate EntityCollections in any business processes element except a script task. So probably it will be a good idea to continue processing the collection in the script task where it was created. Transferring collections might consume a lot of the application resources and decrease the performance if the collection is large.  

Additionally, please don't use "throw new Exception" at all. The fact that you use it means that you literally generate errors in the application. C# and JS code should not contain errors. It should communicate with a user in a regular way. 

Eugene Podkovka,

Hi Eugene, so the idea of sharing an EntityCollection created by ESQ on a script task using process parameters is not supported. correct?

I can put all the code inside a single script task but it will make it too big, the idea is to have different subprocess applying different filters.

Is there any other way to share at least a list of Ids between processes? I don't need a full entity only the ids are enough.

Eugene Podkovka,

Thank you for the answer, the throws new Exceptions are there to verify that the data is correct. I don't want the process running if it has missing information. 

How else can i leave the error on the process log?

Luciano De Munno,

I can't say that it's not supported, but it will be hard to do. The reason is that it's incorrect to split a single c# functionality between different business processes.
Just write correct c# code. Use different methods or even different classes. Create your own logging that will track all possible exceptions. This is the general way of good clean coding. 

Eugene Podkovka,

So, short answer is not supported.

The idea is to make a quick simple process to filter a list using what's already provided by bpm.

 

thank you for the answer

Log in or register to comment