cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

JSON Output to Infotable Output from API.

AitorP
7-Bedrock

JSON Output to Infotable Output from API.

Hi,

I am developing some App in Thingworx. My mate has developed a an API Rest which If I send some JSON, it returns me another JSON.

I would like to work with this JSON and save info in order to create fields in Mashup and visualize, modify data, create new one, etc, but let's go step by step.

 

Let's Start:

 

The code I will send to the API is the following:

{
    "paramh":"",
    "language":"EN",
    "materialfilter": {
        "Materialid": "XXX",
        "Materialdesc": "XXX",
        "Materialclass": "XXX",
        "Materialsustitutive": "XXX"
        }
}

 

I can introduce some data to the XXX just to filter and get an específic JSON result . For example, If I write 1106 on Materialid, I will recieve the following JSON:

AitorP_0-1628233996527.png

Ok, now, I would like to show this JSON in a table or in same way, but as I recieve a "tree" JSON with fileds inside properties (max 3 levels of the tree) from the objects, I would like to know how must be implemented in Thingworx, is there any way to save all the objects somwhere with all data under each property?Some Table? I don't know.

 

I explain what I have done since now:

 

Just to start, I have created a Mashup to filter the "query" where each Field Text is linked to an Input of a Service of a Think but it does not work yet:

AitorP_1-1628234855009.png

 

The Service is the following:

AitorP_2-1628235007841.png

The output, as you can see on the picture attached is a JSON, the same JSON i pasted before, if I execute just the servide on the Thing, it works well.

 

So please, how can I do to save the objects i recieve from JSON ? Creating a Table? Storing it in some place?

 

Thanks in advance,

 

Aitor.

 

11 REPLIES 11
PaiChung
22-Sapphire I
(To:AitorP)

You can store them in a Stream/ValueStream or last option DataTable.

However why do you need to store them and how are you going to use the stored information?

That will determine which route is likely the better one.

AitorP
7-Bedrock
(To:PaiChung)

Hi PaiChung,

 

Thanks for your answer.

 

My goal is the creation of a mashup similar as this one:

AitorP_0-1628490384797.png

So, as you can see, on the JSON I recieve I have data to show in a Table and I have data to show in a kind of fields.

 

I think I really do not need to store data If I can work with them from JSON to the destination where I really want to show it on the mashup. But the problem is that I do not know how to "store" or "link" the data I recieve to the mashup because as I wrote it, I have different levels on the objects on the JSON.

 

Thanks in advance.

 

Aitor

PaiChung
22-Sapphire I
(To:AitorP)

You will have to convert the JSON into an InfoTable in your service and use that in your mashup (you can do InfoTable inside InfoTable if needed)

AitorP
7-Bedrock
(To:PaiChung)

Hi PaiChung,

 

I got some results to get the Infotable from JSON, here the code (Output as InfoTable, Inputs are Fields linked From Mashup):

AitorP_0-1628582405428.png

First I had to create a Datashape with desired fields:

AitorP_1-1628582468753.png

And here the infotable result:

AitorP_2-1628582521121.png

 

Now, please I need your help because I'm locked with the next 2 steps.

1- Is it possible to filter or to add a condition inside the AddRow function? I want to write something to Class Filed Only if the Read data is different to "[]" but a can't get it. (Green line)

AitorP_4-1628583416719.png

2- On the Mashup, I want to click in some row of the grid and execute another service. I have linked the selectedRows binding to an infotable input of another service because I want to convert that infotable data to json data to recieve more info about the selected rows.

If I just test the service, adding manual inputs on the infotable input, it does not convert to json, it converts to table:

AitorP_8-1628586879260.png

 

But if I select text as output, it is convertet to text:

AitorP_9-1628586942822.png

 

Thanks in advance,

 

Aitor

PaiChung
22-Sapphire I
(To:AitorP)

Since most of the ThingWorx resources services and snippets are focused around InfoTable. Personally I would work with the infotable and add/remove whatever is needed and only at the very end convert it to the output you want.

So I don't see an issue with using the table selection and working with the table (it is quite similar to a JSON array)

Else you can use things like ToJSON/ToInfoTable JSON.Stringify/Parse.

As far as conditions before the addrow ... you can do any type of validation you want and you can modify the 'new row' object any which way you need before executing an addrow.

AitorP
7-Bedrock
(To:PaiChung)

Hi,

But, How can i pass the selected rows of an infotable to execute a Service with that data selected? I would like to link the selected row to the input of the service. I use the SelectedRow property and the Double clicked proporte but it does not work.

 

Thanks

 

PaiChung
22-Sapphire I
(To:AitorP)

In the Data panel, expand your source it will have All Data and Selected Row, expand selected row, select the field which you want to use as input, drag and drop that one to your input parameter.

AitorP
7-Bedrock
(To:PaiChung)

Hi,

The option is no shown on this grid. Mmmm...I have 2 grids, 4 fields ans 1 BTN.

The search boton is working correctly, if I introduce something into these fields, I see the Data on the left grid.

When the data is on the left grid, I want to click to some row and use the Value of the Column "ID" of the row selected as an input of another service.

And then, the result of this second service, show into the right grid.

 

But I can't pass the field as input of the second service.

AitorP_0-1628602615866.png

 

Thanks,

 

 

 

PaiChung
22-Sapphire I
(To:AitorP)

Selected Row is part of the Data Source not the Grid (although I believe Collection and Advanced Grid do have some property for it)

AitorP
7-Bedrock
(To:PaiChung)

Hi,

Ok, So how would you do it? Because I am locked right now.

slangley
23-Emerald II
(To:AitorP)

Hi @AitorP.

 

Since this thread is getting quite long, it might be a good idea if we open a case for this post.  If you have a support contract, please private message me with the company account number and associated email address, and I will be happy to open the case on your behalf.

 

Regards.

 

--Sharon

Announcements


Top Tags