Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
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.
Solved! Go to Solution.
The error seems to be for typecasting ....whats your output basetype ? make sure it is of base type 'infotable'.
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,
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;
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
The error seems to be for typecasting ....whats your output basetype ? make sure it is of base type 'infotable'.
That's it. Thanks!