Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Hello There,
i have an Infotable that contains a nested infotable. Let's call them parent and child infotable. I'm able to add anything to the parent and update if i want. For the child infotable i'm somehow limited. I'm only able to add entries with AddRow() but update is not possible.
This is the code i'm using for testing that:
// check if an entry already exist and apply to the variable named project
let project = Things["test.outer.DT"].QueryDataTableEntries({
query: {
"filters": {
"type": "And",
"filters": [
{
"type": "EQ",
"fieldName": "timeStamp",
"value": timeStamp
},
{
"type": "EQ",
"fieldName": "position",
"value": position
}
]
}
} /* QUERY */
});
// create empty holder for the outer DT
let values = Things["test.outer.DT"].CreateValues();
// create empty holder for the inner DT
let versionData = DataShapes["test.inner"].CreateValues();
// create empty holder if no entries exist at the inner DT
let innerValues = new Object();
// check if an entry already exist and apply it to values if so
if(project.getRowCount()){
values = project;
}else {
values.timeStamp = timeStamp;
values.position = position;
// versionData is the nested Infotable
values.versionData = versionData;
}
// check if the inner Infotable has an entry
entry = Resources["InfoTableFunctions"].Query({
t: values.versionData /* INFOTABLE */,
query: {
"filters": {
"type": "EQ",
"fieldName": "versionName",
"value": versionName
}
}
});
// if the inner Infotable has an entry change the property state to hit
if(entry.getRowCount()){
entry.state = "hit";
Resources["InfoTableFunctions"].UpdateQuery({
t: values.versionData /* INFOTABLE */,
query: {
"filters": {
"type": "EQ",
"fieldName": "versionName",
"value": versionName
}
} /* QUERY */,
values: entry /* INFOTABLE */
});
}else{
innerValues.versionName = versionName;
innerValues.State = State;
// add the new entry to the inner Infotable
values.versionData.AddRow(innerValues);
}
// update the hole entry at the outer Infotable
Things["test.outer.DT"].AddOrUpdateDataTableEntry({
values: values /* INFOTABLE */
});
Everything works beside the "UpdateQuery". I tried with "AddOrUpdateDataTableEntry" on values.versionData but i get there an error since it is no real existing Infotable. After few testings and tries i found this: update nested Infotable but i dont get why it doesn't work.
Or is Thingworx not designed for nested Infotables even when it's possible?
in entry i have the changes but UpdateQuery does not update anything.
Solved! Go to Solution.
Okay, who ever will use this UpdateQuery should know that this command is actually a copy command and not an update command (thanks for the wrong and confusing naming).
That means, if you use it, then the return of UpdateQuery will be a changed copy of the matched query. while the original table is untouched.
i use now this workaround
values.versionData.rows.toArray().forEach((row,e) => {
if(row.versionName == versionName){
row.State = State;
}
}
and then the "AddOrUpdateDataTableEntry" will actually do the rest.
Okay, who ever will use this UpdateQuery should know that this command is actually a copy command and not an update command (thanks for the wrong and confusing naming).
That means, if you use it, then the return of UpdateQuery will be a changed copy of the matched query. while the original table is untouched.
i use now this workaround
values.versionData.rows.toArray().forEach((row,e) => {
if(row.versionName == versionName){
row.State = State;
}
}
and then the "AddOrUpdateDataTableEntry" will actually do the rest.