Skip to main content
1-Visitor
January 4, 2018
Solved

Extension with API

  • January 4, 2018
  • 1 reply
  • 3995 views

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.

Best answer by rnayak-2

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

1 reply

5-Regular Member
January 8, 2018

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-31-VisitorAuthor
1-Visitor
January 10, 2018

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;

5-Regular Member
January 10, 2018

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 !