I am trying to save data from an API call, it returns a collection of records. I wish to save these into a table. I do not know how to loop through this collection and save each as a record. Please advise.

Like 0

Like

2 comments
Best reply

Hi Pascal,

 

This can be achieved via OOTB no-code tools of Business Processes.

The response collection of an API can be sent to a sub-process with parameter filled and it can be set to run sequentially so that all the response data will be successfully inserted into the table.



Here is the article, https://customerfx.com/article/working-with-collections-from-a-web-service-element-in-a-process-in-creatio/

 



BR,

Bhoobalan Palanivelu.

Hi Pascal,

 

This can be achieved via OOTB no-code tools of Business Processes.

The response collection of an API can be sent to a sub-process with parameter filled and it can be set to run sequentially so that all the response data will be successfully inserted into the table.



Here is the article, https://customerfx.com/article/working-with-collections-from-a-web-service-element-in-a-process-in-creatio/

 



BR,

Bhoobalan Palanivelu.

The subprocess method is very poor performance for larger datasets though, and so when we had this problem we ended up having to write C# for it. These aspects need to be improved by Creatio if their desire is to continue to push their platform as being effective at scale with no code solutions.

Show all comments

I have a business process that reads a collection of data.

Two of the fields that are being read are datetime fields.

Because the read data process reads many rows, I'm reading those rows in a script task and using the following code:

 

var ProductLines = Get>("ReadDataUserTask1.ResultCompositeObjectList");

    foreach(var ProductLine in ProductLines) {

 

It's very important to understand that inside the foreach loop I'M NOT TRYING TO GET THE DATETIME FIELDS, BUT OTHER STRING TYPE FIELDS.

 

Once I run the process I get the following error message:

Terrasoft.Common.UnsupportedTypeException: Type "System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" is not supported.

   at Terrasoft.Common.CompositeObject.Add(String key, Object value)

   at Terrasoft.Common.CompositeObjectListUtilities.Transform(ICompositeObject source, IReadOnlyDictionary`2 keyMap)

   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()

   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)

   at Terrasoft.Common.CompositeObjectListUtilities.Transform[T](IEnumerable`1 source, IReadOnlyDictionary`2 keyMap)

   at Terrasoft.Core.Process.Configuration.ReadDataUserTask.FillResultCompositeObjectList(IProcessParametersMetaInfo schemaElement, EntityCollection entityCollection)

   at Terrasoft.Core.Process.Configuration.ReadDataUserTask.InternalExecute(ProcessExecutingContext context)

   at Terrasoft.Core.Process.ProcessActivity.ExecuteElement(ProcessExecutingContext context)

   at Terrasoft.Core.Process.ProcessActivity.ExecuteItem(ProcessExecutingContext context)

   at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

 

I'm looking forward to having your assistance with the issue.

 

Best Regards,

Raz

Like 0

Like

1 comments

Hi Raz, 

 

Could you please provide a full script-task code you use so we will be able to test it at our end?

 

Regards,

Anastasiia

Show all comments

I have been struggling very much with handling collection type response parameters in web services.

When response parameters are or normal type they are very easy to handle in the business processes. Here we are able to handle them as parameters on the Call web service process element. And use these in the process right away.

When there is a Collection which is returned, this is very different. Now the Call web service element parameter is of type Collection of Objects with attributes.

It seems to me that this parameter-type is very difficult to handle in the business process. I can't seem to find documentation in the Academy about how to extract and loop through the contents of the Collection of Objects with attributes.

What I have found in the academy is this article about setting up the Web service.

https://academy.bpmonline.com/documents/administration/7-14/adding-resp…

What I need to learn is how to handle them in bpm'online business processes.

Is there something about this in the Academy?

Is writing source code the only option? It's difficult to debug.

Like 0

Like

6 comments

Dear Julius,

Unfortunately, it is impossible to handle parameters that have the “collection of object” type without using the source code.

Therefore, in this case we recommend using “ScriptTask” element for both calling the web-service and processing the results of call.

For more detailed assistance, please contact technical support.

Best regards,

Norton

Norton Lingard, Thank you. Is there anything like this in the academy? Because there is a special bpm'online syntax to go by in the source-code.

Dear Julius,



The service call in a "Script task” business process element can be implemented via native C#. Please find a lot of examples on how to do that in Google. For example, several links below:



https://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c



https://code-maze.com/different-ways-consume-restful-api-csharp/

Please note that it is possible to use the native C# collections instead of working with the the special bpmonline collections.

Best regards,

Norton

Hi Julius,

 

Did you manage to solve this?

 

I'm struggling with the same issue and didn't manage to get it to work.

 

Looking forward to having Your answer.

 

Raz

Norton Lingard,

Hi Norton,

 

Is there another example on how to do it in the script task?

 

I tried implementing it based on the links you posted and I'm getting many error messages when posting the code.

 

Thanks,

Raz

Dear Raz,

 

Please find another example in the article by the link below:

 

https://stackoverflow.com/questions/3900371/how-can-i-call-a-webservice-from-c-sharp-with-http-post

 

If you still can’t resolve the issue please provide us with a source code that you wrote and errors that you got.

 

Best regards,

Norton

Show all comments

Hi,

I'm trying to get a list of OpportunityFile associated with an OpportunityId and it's seems it's not possible using ODATA.

1. If I'm using this Url https://server.bpmonline.com/0/ServiceModel/EntityDataService.svc/Oppor… I'm getting a "Not Implemented" exception

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<script/>
<code>4

Not Implemented

Not Implemented
System.Data.Services.DataServiceException

at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)
at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService, IODataResponseMessage responseMessage)
at System.Data.Services.DataService`1.HandleRequest()

Method 'SelectMany' not supported
System.NotSupportedException

at Terrasoft.Core.Entities.EntityQueryProvider.VisitMethodCall(MethodCallExpression node)
at Terrasoft.Core.Entities.EntityQueryProvider.Build(Expression expression)
at Terrasoft.Core.Entities.EntityQueryProvider.LoadEntityCollection(Expression expression)
at Terrasoft.Core.Entities.EntityQueryProvider.ExecuteEnumerable(Type elementType, Expression expression)
at Terrasoft.Core.Entities.EntityQuery`1.GetEnumerator()
at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)

2. If I'm using this Url https://server.bpmonline.com/0/ServiceModel/EntityDataService.svc/Oppor… eq guid'e14b9eb7-99ff-43a6-bf26-a60b23b3ec12') I'm getting the following exception:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<script/>
<code>1

Collection item with name OpportunityId not found.

Collection item with name OpportunityId not found.
Terrasoft.Common.ItemNotFoundException

at Terrasoft.Core.Entities.EntitySchema.GetSchemaColumnByPath(String columnPath)
at Terrasoft.Core.Entities.EntityQueryWhereBlockBuilder.CreateExpression(Expression node)
at Terrasoft.Core.Entities.EntityQueryWhereBlockBuilder.CreateSimpleFilter(BinaryExpression binary)
at Terrasoft.Core.Entities.EntityQueryWhereBlockBuilder.CreateFilter(Expression node)
at Terrasoft.Core.Entities.EntityQueryWhereBlockBuilder.BuildBlock(MethodCallExpression node)
at Terrasoft.Core.Entities.EntityQueryProvider.VisitMethodCall(MethodCallExpression node)
at Terrasoft.Core.Entities.EntityQueryProvider.Build(Expression expression)
at Terrasoft.Core.Entities.EntityQueryProvider.LoadEntityCollection(Expression expression)
at Terrasoft.Core.Entities.EntityQueryProvider.ExecuteEnumerable(Type elementType, Expression expression)
at Terrasoft.Core.Entities.EntityQuery`1.GetEnumerator()
at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)
at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService, IODataResponseMessage responseMessage)
at System.Data.Services.DataService`1.HandleRequest()

3. Also, if I'm using this Url https://server.bpmonline.com/0/ServiceModel/EntityDataService.svc/Oppor… eq guid'b3427cc4-3b20-4c16-8d2a-058ada7e7631') I'm getting a different error.

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<script/>
<code>4

Syntax error at position 1.

Syntax error at position 1.
System.Data.Services.DataServiceException

at System.Data.Services.Parsing.ExpressionLexer.ValidateToken(TokenId t)
at System.Data.Services.Parsing.ExpressionLexer.ReadDottedIdentifier(Boolean allowEndWithDotStar)
at System.Data.Services.RequestQueryProcessor.ReadExpandOrSelect(String value, Boolean select, IDataService dataService)
at System.Data.Services.RequestQueryProcessor.ProcessSelect()
at System.Data.Services.RequestQueryProcessor.ProcessQuery()
at System.Data.Services.RequestQueryProcessor.ProcessQuery(IDataService service, RequestDescription description)
at System.Data.Services.RequestUriProcessor.ProcessRequestUri(Uri absoluteRequestUri, IDataService service, Boolean internalQuery)
at System.Data.Services.DataService`1.HandleRequest()

It seems the filtering is not working on associated collection entities. Do you have any ideas?

Regards,

Radu

Like 0

Like

1 comments

Dear Radu,

Please see the example below. Draw your attention to the column OpportunityId syntax - Opportunity/Id

 

http://localhost:8006/0/ServiceModel/EntityDataService.svc/OpportunityF… = Opportunity/Id eq guid'410006e1-ca4e-4502-a9ec-e54d922d2c00'

 

Regards, 

Anastasia

Show all comments



Hello community!

I need get in a bussines process a collection parameter and then use that in a script task into a foreach. Any example about that?

 

Regards,

 

Like 0

Like

5 comments

Dear Federico,

Please check the instructions on how to work with collections within [Read data element]. This will help you to implement your own process.



Algorithm of the work with a collection from Read data:



1.Disable the formula validator in business process designer. You can open the console and execute the following script for that:

var featureCode = "UseProcessFormulaServerValidation";

require(["FeatureServiceRequest"], function() {

                var featureRequest = Ext.create("Terrasoft.FeatureServiceRequest", {code: featureCode});

                featureRequest.updateFeatureState({

                               forAllUsers: true,

                               state: Terrasoft.FeatureState.DISABLED // ENABLED

                }, ()=>console.log("Done"));

});

 

2. In [Read data] element go to extended options and tick:

Read first = true

Number of records to read = 100 //Number of records available in a collection.



3. Create a process parameter with EntityCollection type and map it to the resulting collection of [Read data]. This parameter does not exist out of the box, but you can create it manually. 

Example:

[#MyRead.Resulting collection#]

*  MyRead – [Read data] element header.

* Resulting Collection - added manually

 

4. Assign a process parameter to a new variable in ScriptTask. Here is the example how to process the collection:

EntityCollection entities = Get("MyEntity");

var result = new Collection();

foreach(Entity entity in entities) {

                var cityName = entity.GetTypedColumnValue("Id");

                string temp = cityName.ToString();

                result.Add(temp);

                }

 

string displayValue = result.ConcatIfNotEmpty(",");

Set("MyResult", displayValue);

return true;

 

MyRead – reading datat in any element.

MyEntity process parameter with EntityCollection type. Parameter value= [#MyRead.Resulting collection#]

MyResult - string parameter. You can store record IDs from the collection. Then this parameter is shown on the auto generated page for the testing purposes.  

Best regards,

Lily

Lily Johnson,

Hello,

I tried the above script task as below:

EntityCollection entities = Get("MyEntity");

var result = new Collection();

foreach(Entity entity in entities) {

                var productName = entity.GetTypedColumnValue("Name");

                string temp = productName.ToString();

                result.Add(temp);

                }

string displayValue = result.ConcatIfNotEmpty(",");

Set("UsrLatestOrderProduct", displayValue);

return true;

 

But, here I'm getting below errors:

 

Lily Johnson,

Hello,

 

Can you elaborate on how Auto-Generated Page works upon this case? 

 

Many Thanks

Riddhi Jadeja,



As we can see from the screenshots you have provided - GetTypedColumnValue is used incorrectly. 

GetTypedColumnValue("Name") is used without specified type of this field. 

It should be GetTypedColumnValue<string>("Name")



Kind regards,

Roman

Sarthak Jain,



Can you please specify your question with more details? 

How exactly Auto-Generated Page will be related to the discussed case? 



Thank you in advance,

Roman

Show all comments