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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

AddRow won't work if field is added runtime

fmanniti
9-Granite

AddRow won't work if field is added runtime

I have a datashape with some fields in it, then I have a "if" condition where I add two more fields to my table but when I add the values using AddRow to those two fields, they won't work.

Here's the code for more details:

var template = Things[entityName].thingTemplate;

var params = {

    infoTableName : "InfoTable",

    dataShapeName : "GeneralPropertiesTableShape"

};

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

propertiesTable.AddRow({

    label: Things[entityName].label,

    strain: Things[entityName].strain,

    tiltX: Things[entityName].tiltX,

    tiltY: Things[entityName].tiltY,

    tiltZ: Things[entityName].tiltZ,

    temperature: Things[entityName].temperature,

    seismic: Things[entityName].seismic

});

switch(template){

    case('PointThingTemplate'):

        propertiesTable.AddField({name:"substrate", baseType:"STRING"});

        propertiesTable.AddRow({substrate: Things[entityName].substrate});

        break;

}

my result is I can see the new field "substrate" but I see it empty

1 ACCEPTED SOLUTION

Accepted Solutions
jamesm1
5-Regular Member
(To:fmanniti)

Hey Fabio,

Which version of TWX is this on? I ran your sample snippet and got the expected results:

If you want them to be on the same row, you would have to modify your code slightly to create a row object, add the additional field in the if statement, and add the row at the bottom. Note that this field wont be visible in the mashup builder because it has no way to know that this field is there in design time.

Thanks,

-James

View solution in original post

3 REPLIES 3
jamesm1
5-Regular Member
(To:fmanniti)

Hey Fabio,

Which version of TWX is this on? I ran your sample snippet and got the expected results:

If you want them to be on the same row, you would have to modify your code slightly to create a row object, add the additional field in the if statement, and add the row at the bottom. Note that this field wont be visible in the mashup builder because it has no way to know that this field is there in design time.

Thanks,

-James

Ok, perfect.

I was only showing one row, that's why I saw it empty.

Problem solved.

Thank you

jamesm1
5-Regular Member
(To:fmanniti)

I modified your snippet slightly so that it will all be on one row:

var template = Things[entityName].thingTemplate; 

var params = { 

    infoTableName : "InfoTable", 

    dataShapeName : "GeneralPropertiesTableShape" 

}; 

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

var row = { 

    label: Things[entityName].label,  

    strain: Things[entityName].strain, 

    tiltX: Things[entityName].tiltX, 

    tiltY: Things[entityName].tiltY, 

    tiltZ: Things[entityName].tiltZ, 

    temperature: Things[entityName].temperature, 

    seismic: Things[entityName].seismic 

}

switch(template){ 

    case('PointThingTemplate'): 

        propertiesTable.AddField({name:"substrate", baseType:"STRING"}); 

        row.substrate = Things[entityName].substrate; 

        break; 

}

 

propertiesTable.AddRow(row); 

result = propertiesTable

Top Tags