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

How to update each index of infotable rows which is already created in userextension.

AP_10343008
13-Aquamarine

How to update each index of infotable rows which is already created in userextension.

I have added infotable property in userextensions. When iam updating every index of infotable, this folloeing error is poping up. How to update each index of infotable rows which is already created in userextension.
Error: JavaException: java.lang.ClassCastException: com.thingworx.types.InfoTable cannot be cast to com.thingworx.types.collections.ValueCollection

3 REPLIES 3

Hi @AP_10343008 

 

Based on your error message: You are trying to add ValueCollection to InfoTable variable. 

 

It will be helpful if you post your code to debug it

 

The below script is used to add a new row to user extension

var infoTableValue = Users["Administrator"].testp;

infoTableValue.AddRow({
	f1: "t1",
	f2: "t2"
});

infoTableValue.AddRow({
	f1: "t3",
	f2: "t4"
});

Users["Administrator"].testp = infoTableValue;

var result = Users["Administrator"].testp;

 

To update infotable value

var infoTableValue = Users["Administrator"].testp;

for(var i = 0 ; i < infoTableValue.length; i++)
{
    if(infoTableValue.rows[i].f1 === "t1")
    {
        infoTableValue.rows[i].f2 = "Changed";
    }
}

Users["Administrator"].testp = infoTableValue;

var result = Users["Administrator"].testp;

 

/VR

AP_10343008
13-Aquamarine
(To:Velkumar)

Example: I have 15 rows in Users["Administrator"].testp
Based on change event, iam running same service 15 times to update each row[index] of infotable. 

So i need a code to update only particular row in user extension property directly not the full infotable. 
I tried the below code by directly passing index number of infotable but it doesnt worked.

newEntry.AddRow({colA : "A", colB : "B"});

Users["Administrator"].testp[1] = newEntry;

Hi @AP_10343008 

 

If you know the index of the row 

 

// Get value from User extension and store it in InfoTable
var infoTableValue = Users["Administrator"].testp;

// update row value based on index
infoTableValue.rows[INDEXNUMBER].f1 = "directValue"; 

// Update User extension value
Users["Administrator"].testp = infoTableValue;

// Return result to validate data
var result = Users["Administrator"].testp;

 

/VR

Top Tags