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

Dynamic Thing Properties Reference

Visitor

Dynamic Thing Properties Reference

Hello,

 

I am trying to setup a loop that will cycle through a thing's properties based off a number and then add those values to an infotable. I don't know how to incorporate the variable number into the reference to the thing's properties though. See below code.

 

var params = {

infoTableName : "InfoTable",

dataShapeName : "TC1_LBCSS_Soak_Tank_Information"

};

 

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

 

for (var i = 1; i <=14; i++){

        

    tempresult.AddRow({

    Soak_Tank: i,

    Status: me.LB1_Soak_Tank_& i &_Status,

    Condition: me.LB1_Soak_Tank_& i &_Process_Status,

    Soak_Time: me.LB1_Soak_Tank_& i &_Soak_Time,

})

}    

    var result= tempresult

 

When doing it this way I receive an error. What is the correct way to incorporate the number reference inside the reference to the Thing's properties?

 

 



2 REPLIES 2

Dynamic Thing Properties Reference

Hi Michael, how have you been?

JavaScript does it a little different.

I would do it as follows:

me["LB1_Soak_Tank_" + i + "_Process_Status"]


A cleaner way would be to create the strings before you use it so:

var tmpProcStat = "LB1_Soak_Tank_" + i + "_Process_Status"

me[tmpProcStat]



Dynamic Thing Properties Reference

Pai,


I've been great, busy making wonderful tools with Thingworx! Thanks for the help with the code, this did the trick. I knew how to do it in VBA just wasn't sure with Javascript. Hopefully your workload will get a little easier with the release of 5.0!