Dynamic parameters for web service

Hi,

I'm trying to pass the result of below "json" (in script task),

var schema = UserConnection.EntitySchemaManager.GetInstanceByName("Account");

    var entity = schema.CreateEntity(UserConnection);

    entity.FetchFromDB(id);

    json = Terrasoft.Core.Entities.Entity.SerializeToJson(entity);

 

to a process parameter and that process parameter needs to be passed to web service element as an request object. Since, the structure of "json" variable might vary, how to send this to a process parameter and eventually to web service element?

 

Any suggestions would be appreciated. Thanks.

Like 2

Like

5 comments

public bool FetchFromDB(object keyValue, bool useDisplayValues = true)

All the `FetchFromDB` methods return a bool, you could test the call.

SerializeToJson(Entity)

Should work.

 

I've had a great deal of trouble with JSON in Creatio in the past.   What's the error you're getting?

Hi Gareth,

Thanks for your reply.

Is there a sample as how this can be sent to webservice element? Use case is to handle this as an object while sending it to webservice element and not as a string. For example, the request at the web service element should look like below.

{

"objectName" : "Contact",

"Payload" : { "Name" : "Halludeen", "Age" : 24 }

}

But, if I pass it as a string then it looks like,

{

"requestJson" : "{\r\n \"ObjectName\": \"Contact\", \r\n \"Payload\": { \"Name\" : \"Halludeen\"}"

}

 

Let me know if you have any suggestions for this.

 

Thanks again.

 

 

 

Halludeen,

The only JSON library I have been able to get to work in Creatio is 

`System.Text.Json.JsonSerializer`.  You have to call it with the full namespace rather than add the namespace in a `using` statement, see here.

 

You could use the `Serialize<TValue>(TValue, JsonSerializerOptions)` method.  The technique is essentially the reverse of the example linked to above, create an object for the deserialised JSON in a module (see example), add the namespace to your process, create an object with the data you want to serialise, and serialise it using the above method into a string.  Hopefully that will work!

Gareth Osler,

Having said the above, I wrote in June,

By way of an epilogue, while the `System.Text.Json` namespace is available in a trial, for some reason it was not available in the dev environment I was using.  However classes in the `Terrasoft.Common.Json` namespace were available.  I was able to use the `Deserialize<T>(String)` method of the Json class.  (Note at the time of writing the `DeserializeDictionary(String)` method has a bug in it and cannot be used.)

You may have to use the above class to do the same.

Show all comments