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

Extension with API

SOLVED
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.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Extension with API

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

Re: Extension with API

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

Re: Extension with API

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;

Re: Extension with API

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 !

Re: Extension with API

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

Re: Extension with API

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

View solution in original post

Re: Extension with API

That's it. Thanks!

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________