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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

InfoTable as User Extension is not working fine

mbereket
3-Newcomer

InfoTable as User Extension is not working fine

Hi,

So, I needed to add an extra attribute to user extensions and that attribute has to be an infoTable.

- I added this "customDashboard" infoTable attribute to UserExtensions to keep some data for each user.

Now I am trying to add/update that infoTable but for some reason it wouldnt let me addRow(item).

---------

var item = Object();

item.device_uuid = device_uuid;

item.sensor = sensor;

Users[username].customDashboard.AddRow(item);

-------

and the error its giving is following:

TypeError: Cannot find function AddRow in object . (addDashboardItem#4)

​Does anyone have any idea about how this happens?


Thanks,

4 REPLIES 4

What I'm suggesting below should work and be the proper way to set an InfoTable property, but it appears that there is actually a bug when going to programmatically set that value. The defect was found in version 7.1.3 of ThingWorx and the status can be tracked in this article.

Even going about it by using the setConfigurationTable service is not clear because of the basetypes that are accepted for the "value" parameter when updating each field.

Something like this would be how I would typically recommend just setting an InfoTable property:

var params = {

  infoTableName : "InfoTable",

  dataShapeName : "TestingUserExtensions"

};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(TestingUserExtensions)

var tempTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

// TestingUserExtensions entry object

var newEntry = new Object();

newEntry.sensor = sensor_value; // STRING

newEntry.device_uuid = device_uuid_value; // STRING

Users["Administrator"].customDashboard = tempTable;

I first created an InfoTable based on the InfoTable User Extension property's DataShape. Then I added an entry to that InfoTable based on the same DataShape. Then I have finally set the property to this InfoTable.

Meghan

Thank you for your reply, but I didnt quite get the following part:

var params = {

  infoTableName : "InfoTable",

  dataShapeName : "TestingUserExtensions"

};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(TestingUserExtensions)

var tempTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

So, do you think I need to do this each time when I use my update userExtension service? then how am I going to keep the data consistent?

all I wanted to do is to stick an InfoTable to each user I create and keep their customDashboard info and be able to insert/delete/update when I needed to.

So that is actually why I went to system objects and added that customDashboard attribute to "UserExtension DataShape".

After looking into this further I have discovered another bug that I've reported to R&D and can be followed here: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS242472&lang=en_US

Below is how to add rows to an InfoTable that's in JSON format:

// Grab the InfoTable that is nested inside the InfoTable property

var temp = me.testing.rows[0].nestedTable;

temp = temp.ToJSON();     // Convert that InfoTable Object to JSON format

// Create a new entry to push onto the JSON Object

var newEntry = new Object();

newEntry.sensor = "Meg-o";

newEntry.device_uuid = "heh";

var obj = JSON.parse(temp);

obj['rows'].push(newEntry);

temp = JSON.stringify(obj);

var result = temp;

I'm providing the push solution instead of using the AddRow() snippet because it looked like the error you were receiving regarding AddRow not being found on that InfoTable means that it was already in JSON format and not an InfoTable object.

Again, I can't seem to get this working with an InfoTable property on a User, and this may be because the properties of a User are actually stored in a Configuration Table. There may be some variation in the way InfoTables are handled there.

Meghan

Thank you so much, I will look into this and see if it works.

Announcements


Top Tags