Question

Process WebService result in c# script

Hi community!

How are you?

I have a web service configured which returns an object collection among others parameters

Through a business process, I want to process the response of said web service.

For this, I have configured a parameter in the process..







To which, I assign the collection result of the WS as follows:

 


 

Then, in the script, I try to read the collection parameter in a variable..



The process compiles successfully, but when executing it, I get the following error

I tried several alternatives, like



var entities = Get>("Tickets");



or another data type but I keep getting the same error

Any idea or example to process a collection of a web service?

 

(My BPM version is 7.13)

I attached the images to be seen more clearly

Thanks you!



King Regards

 

Ezequiel

Like 0

Like

9 comments

Dear Ezequiel,

Please see the step-by-step instruction on how to correctly retrieve and work with web service collection result in business process Script Task. 



1. To start with, here are my test web service integration settings:

Image.png



Image.png





2. In the business process we will be retrieving needed data directly from the Web Service element. 

The main idea here is to address the results collection via "_Out" suffix. Please pay attention, that we apply suffix to the method's parameter and each variable taken from the collection.









Image.png

 Regards,

Anastasia

AAlonso.29,

Hello.

Please find all of the images via the links below:

https://prnt.sc/m5x10n

https://prnt.sc/m5x0wj

https://prnt.sc/m5x2b5

https://prnt.sc/m5x2me

Best regards,

Matt

Hello Matt

I configured exactly the web service and the business process as in you screenshots but the following statement (My custom prefix is Rv instead of Usr)

var entities = Get<ICompositeObjectList<ICompositeObject>>("WebService1.RvArray_Out");

returns a null variable (entities is null).

The web service response is OK (I tried to show it on a page).

I also tried using this syntax:

var entities = Get<EntityCollection>("WebService1.RvArray_Out");

but the entities variable is still null.

Can you tell me what's wrong with my code?

Thank you very much

 

Massimiliano Mazzacurati,

It seems that webservice simply is not returning the desired array. To confident about this, you may create some test queries to the webservice in postman or fiddler (utilities for web development).  



However, you always can call the webservice in script task via c# code and then process the response from the webservice as you wish.

https://stackoverflow.com/questions/4015324/how-to-make-http-post-web-request



Best regards,

Alex

Hi,

I have a web service from which i fetching data like name, mobile number, email address. Response that is returned is an array. Now want to fetch email address and sent email to all the customers. I have attached the process diagram and task script :

Below is the script for fetching data from web service response: where can see console logs in creatio like values of name and email that have printed in the console.Writeline.

 

UsrParameter is the code of the response parameters. 

When i am sending simple response parameters like name and email script works without any error but when i send array as response i am getting error.

 

var entities = Get<ICompositeObjectList<ICompositeObject>>("WebService1.UsrParameter_Out");

foreach(var entity in entities){

    

     string name="";

     string email="";

     var isnameexist = entity.TryGetValue<string>("UsrName_Out", out name);

      throw new Exception(name);

    

     var isemailexist = entity.TryGetValue<string>("UsrEmail_Out", out email);

    throw new Exception(email);

    

     Console.WriteLine("name "+name);

      Console.WriteLine("email "+email);

     Console.WriteLine("isnameexist "+isnameexist);

      Console.WriteLine("isemailexist "+isemailexist);

    

}

return true;

 

Please help me solve this issue. I am new to creatio. I am struggling with script task element.

 

Thanks 

Nitin

Nitin,

 

Hello,

 

Try composing your approach with the one developed in the "Prepare Recipient Emails" script-task of the base "Send email to case group" business process:

The idea here is to form a list of recipients from a collection of the ESQ request result. You need to use your collection and develop a logic similar to the one developed in the script task.

 

Best regards,

Oscar

Oscar Dylan,

 

Thank you Oscar for reply 

Massimiliano Mazzacurati,

 

When we are fetching responses  from a web service,What is this "WebService1" in the double quotes? From where i can map this value?

Nitin,



here in advanced mode 

you can see the code for webservice and its parameters on 2nd tab

Show all comments