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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Why? ThingworxInfoTableAdapter cannot be cast to com.thingworx.types.InfoTable

mboyle
1-Newbie

Why? ThingworxInfoTableAdapter cannot be cast to com.thingworx.types.InfoTable

Here is quick outline of my service. When I run this inside of Thinkworx as a service, I get 4 data rows. Perfect. So now I want to return json and below are my attempts (logged). Any ideas on why this error occurs? I have tried every json-converter function I can find.

var DetailedLogging = true;

logger.warn("here is my input value....." + lastDTSCheck);

try {

    var devices = Things['ATS.Org'].ListDevices();

    var device;

    var result = null;

    result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({

       infoTableName : "InfoTable",

        dataShapeName : "OrgDateCheck"

    });

    var cnt = 0;

    for each(device in devices.rows) {

        device = Things[device.EntityName];

       

        if (device.GetLastModifiedDate() > lastDTSCheck) {

            cnt = cnt + 1;

            logger.warn("My counter is now at: " + cnt);

           if (result == null) {

               result = Things[device.name].GetPropertyValues();

               result.name = device.name;

           } else {

               result.AddRow(Things[device.name].GetPropertyValues().rows[0]);

               result.rows[result.getRowCount() - 1].name = device.name;

           }

        }

    }

    //logger.warn("debugging the output? ..... " + result);

    //logger.warn("debugging the output 2 as json string" + result.ToJSON() );

    //logger.warn("debugging the output 3 as stringify: " + JSON.stringify(result) );

    //logger.warn("debugging the output 4 as toString: " + result.toString() );

    //result = JSON.stringify(result);

    result.ToJSON();

} catch (err) {

  logger.warn(me.name + ".MEB() [err]: " + err + ", " + err.lineNumber);

}

1 ACCEPTED SOLUTION

Accepted Solutions
jkaczynski
4-Participant
(To:mboyle)

Hello Michael Boyle​,

Have you tried to replace


result.ToJSON();

with

result = result.ToJSON();

? In your code you do not assign the JSON result to the result variable, so the InfoTable (not JSON) is returned. Then just set the output base type to JSON and it should return JSON with InfoTable data.

Regards,

J.

View solution in original post

2 REPLIES 2
jkaczynski
4-Participant
(To:mboyle)

Hello Michael Boyle​,

Have you tried to replace


result.ToJSON();

with

result = result.ToJSON();

? In your code you do not assign the JSON result to the result variable, so the InfoTable (not JSON) is returned. Then just set the output base type to JSON and it should return JSON with InfoTable data.

Regards,

J.

Thanks -- that did solve my problem with getting json data. Alas, it also created a new one: now the service returns ALL of the data and not just the 4 items I was expecting! It is always something!

Top Tags