Solved

Output JSON data via Indicium

  • 7 October 2019
  • 9 replies
  • 373 views

Userlevel 5
Badge +20
I am trying to make a link from a third party application to my Thnikwise application via Indicium.

For this I prefer the use of tasks/stored procedures with output parameters, which works fine.

To minimize the amount of requests I like to return detail data in JSON format as output. It works almost as expected, except that Indicium ads escape characters (backslashes).

Like this:

code:
{
"@odata.context":"https://dev-mob.smarttt.nl/sf/stt/$metadata#STT.complex",
"row_id": "BBF3801D-2E9C-42FC-9D33-182C326867EB",
"item_id": "Jhlkd2awEQLiPSK7B",
"child_rows": "[{\"row_id\":\"80E2F8FDD3B3\",\"image_id\":\"1231\"},
{\"row_id\":\"47F6978E83EE\",\"image_id\":\"1232\"},
{\"row_id\":\"2D40689AFEA2\",\"image_id\":\"1234\"}]"
}


I there any way or trick to get this solved?
icon

Best answer by Vincent Doppenberg 11 October 2019, 16:24

View original

9 replies

Userlevel 6
Badge +4
Hello Harm,

I don't think your problem is that Indicium adds escape characters, I think your problem is that the value of "child_rows" is a singular string literal, rather than a nested JSON array.

What are you looking for is probably a response like the one below. Note that I didn't just remove the escape characters, I also removed the outer quotes.

code:
{
"@odata.context":"https://dev-mob.smarttt.nl/sf/stt/$metadata#STT.complex",
"row_id": "BBF3801D-2E9C-42FC-9D33-182C326867EB",
"item_id": "Jhlkd2awEQLiPSK7B",
"child_rows": [
{
"row_id": "80E2F8FDD3B3",
"image_id": "1231"
},
{
"row_id": "47F6978E83EE",
"image_id": "1232"
},
{
"row_id": "2D40689AFEA2",
"image_id": "1234"
}
]
}


At the moment there is no way to achieve this, but we are working on a way to request a table or view and expand detail references in a single request. This feature should become available in a matter of weeks.

Example:

code:
https://server/indicium/project?$expand=detail_ref_project_sub_project


Result:

code:
[
{
"project_id": 1,
"name": "project name",
"detail_ref_project_sub_project": [
{
"project_id": 1,
"sub_project_id: 1,
"name": "sub project name"
},
...
]
},
...
]
Userlevel 5
Badge +20
Hi Vincent,

This would be a nice extension of the API.

But actually I would prefer a solution that allows me to do one request and get a JSON output with multiple details and even with deeper nested detail levels.
Userlevel 6
Badge +4

Hello @Harm Horstman,

This solution will actually allow you to get JSON output for multiple details in a single request. I'm not sure, however, if deeper nested details will be available as well. At the very least I do not expect deeper nested details to work in our initial implementation.

How many levels will you need to expand and how often do you expect to need this?

Userlevel 5
Badge +20

One level deeper would help already.

Max 5 levels deep, would be perfect.

 

Userlevel 1
Badge +1

Hello @Harm Horstman,

I’m running into the samen problem and I’m wondering what solution you used. I try to return the results of an action performed in a task or stored procedure in JSON format and need to get rid of the escape characters.

@Vincent Doppenberg Can this only be achieved using a new call to get the results needing multiple views for the details?

Userlevel 6
Badge +4

Hello John,

We have since added a way to create fully customizable APIs to the Thinkwise Platform, which allow you to accept any kind of request and return any kind of response, including nested JSON structures.

This can be achieved by creating a process flow with the following checkbox turned on.

 

This allows you to assign request and response properties to process variables, which can be used to process a request yourself and set the response that you want to give.

Anne Buit has written an extensive, two-part blog on this feature:

In particular, the following example from the blog should be interesting to you. The code behind these examples is included in the blog.

Nested structures of JSON objects and arrays in a single response

 

I hope this helps.

Userlevel 1
Badge +1

Hi @Vincent Doppenberg,  thanks for your quick response. It looks like this is exactly what I was looking for.

Userlevel 1
Badge +4

@Vincent Doppenberg , 
does this mean that when having a task or subroutine with a json formatted output parameter, this always will be converted into a string with escape characters?
And the only way to get it properly formatted as json for an API is to use a process flow as API as explained in the blog?

Userlevel 6
Badge +4

Hello @HJ van Dalfsen,

Yes, that is correct.

Indicium outputs its own JSON for tasks and subroutines and the output parameters of these tasks and subroutines, including their values, are simply properties inside of this larger JSON structure. Furthermore, there is currently no JSON data type that can be configured on a domain in the SF, so the values given to these output parameters cannot be JSON, strictly speaking. They are simply (n)varchar values and so they are returned with surrounding quotations marks and the necessary characters are escaped.

With that said, there is no reason to think that the offered solution with process flows is inferior. It's quite simple to configure in the SF, you can make the API identical to that of a subroutine and you have full control over the returned response.

Reply