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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

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

AP_10343008
15-Moonstone

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
Velkumar
19-Tanzanite
(To:AP_10343008)

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
15-Moonstone
(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;

Velkumar
19-Tanzanite
(To:AP_10343008)

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

Announcements


Top Tags