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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Extension with API

asaito-3
3-Visitor

Extension with API

Hi All,

I am trying to use a JSON result from an API call in a grid...but for this, I need to convert the JSON data to INFOTABLE data type.
The question is

: how?
I am creating two services for this, but I don't have a clue if this is the best way to go...
A service that give the JSON from the API call, and another one, that will convert the JSON from the previous one.
Any tips?

Thanks,
Anselmo.

ACCEPTED SOLUTION

Accepted Solutions
rnayak-2
5-Regular Member
(To:asaito-3)

The error seems to be for typecasting ....whats your output basetype ? make sure it is of base type 'infotable'.

View solution in original post

6 REPLIES 6
mgoel
17-Peridot
(To:asaito-3)

Hi Anselmo Saito

Could you please try the below article for the solution:

https://www.ptc.com/en/support/article?n=CS179012

Do let me know in case of any question.

Regards,

Mohit Goel

asaito-3
3-Visitor
(To:mgoel)

It says that I have no Infotable created...but this is exactly what I want to do with some kind of conversor...

Here is my code following what is in this link:

var text = '{ "employees" : [' +

'{ "firstName":"John" , "lastName":"Doe" },' +

'{ "firstName":"Anna" , "lastName":"Smith" },' +

'{ "firstName":"Peter" , "lastName":"Jones" } ]}';


var json = JSON.parse(text);


var params = {

infoTableName : "employees",

dataShapeName : "AlertEvent"

};


// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(AlertEvent)

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


for(var i=0;i<json.length;i++){

    Infotable.AddRow({Name:json.firstName, Value:json.lastName});

    }

//}

result = InfoTable;

rnayak-2
5-Regular Member
(To:asaito-3)

In your for loop you have incorrectly specified as " Infotable.AddRow" which should be actually " result.AddRow". Once you do that you dont need the last line "result = InfoTable" as you are directly adding info from json to your result set. Do this change and run the code again and see if it gives you what you need !

After these changes I received a diferent error message :
com.thingworx.dsl.engine.adapters.ThingworxInfoTableAdapter cannot be cast to com.thingworx.types.InfoTable

rnayak-2
5-Regular Member
(To:asaito-3)

The error seems to be for typecasting ....whats your output basetype ? make sure it is of base type 'infotable'.

That's it. Thanks!

Announcements


Top Tags