6 Replies Latest reply on Jan 11, 2018 12:59 PM by asaito-3 RSS
    asaito-3 Explorer

    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.

      • Re: Extension with API
        mgoel Apprentice

        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
            asaito-3 Explorer

            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[i].firstName, Value:json[i].lastName});

             

                }

            //}

            result = InfoTable;