Pass array/list to Smart Object


Badge +3

I created a SmartObject from an Endpoint Assembly I created. The method accepts List<string> then out a single line of text.

I use the SmartObject in K2 Visual Studio, but i'm struggling to pass a List<string> to the smart, how can I do that?

 

This is what the class library I converted to Endpoint Assembly service object

    public class TestClass {
public static string Combine(List<string> items) {
StringBuilder sb = new StringBuilder();
foreach (string item in items) {
sb.Append(item);
}
return sb.ToString();
}
}

5 replies

Badge +7

Hi,

 

I dont rally think you can pass the list input to SmartObject property. There are some limitations on it. I would recommend you to pass list items with delimiter seperated. then on in your code logic you can still return the String pattern.

 

 

Hope it help!

 

Cheers,

Prajwal Shambhu

Userlevel 1
Badge +8

Hi Rowell,

 

You won't be able to pass a list to the procedure as the List<T> type isn't supported by the broker. If you look under the System Types folder of the Instance you request you will see that only serialization to and from an Array is supported. If you change your input to an arry of string you can then use the methods located under the String type in the System Types folder to build your array to pass to your class method.

 

 

12835iAD5E217999804E9F.png

 

Hope this helps.

 

S.

Badge +3

Thank you @ @Prajwal_Shambhu

 

@ @ScottPCaliber

Thanks for your idea. I have tried this but got confused.

The Method "Serialize Item to Array" only accepts one parameter, does that mean I always need to call "Serialize Add Item to Array" method to add additional items in the array?

Userlevel 1
Badge +8

Yes, there are plenty of options. Like playing with a set of Russian Nesting Dolls.

 

In this case (working from memory) you would start with Serialize then -> Serialize Item to Array to get a new array. Then you would serialize --> Serialize Add Item to Array to add new items to array once you have an array. 

 

I agree it can very very confusing. you might be able to skip the first step Serialize --> Serialize Item to Array and just call serialize item to array first to get an array to get the array and then use the add item to add additional items to the array.

 

Sorry I cannot be more clear. I don't have my VM up in front of me at the moment.

 

S.

Userlevel 1
Badge +8

So this was bugging me, I had to fire up the VM and work this out.

 

You will use Serialize Item to Array to take a single item and create a new array.

 

You will then use Serialize Add Item to Array providing the array from the first step plus your next item to add to the array.

 

Subsequent calls will also use Add Item so you end up with something that looks like: 

{"$type":"System.String[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","$values":["Test","Tst2"]}

 

This value is then passed into your method that requires a string array.

 

If you don't see that string, go into your service instance configuration for your endpoint and set Serialize Compression to false for testing and then turn it back on to keep the packages small for transport.

 

Hope this gets you going again.

 

S.

Reply