Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
I have only one entry in my datatable with 4 fields. One of the field is primary key for that datashape. Now my question is i want to update this entry but that primary key value would also be updated. Now the confusion is how can i do that? I have the service UpdateDataTableEntry and AddOrUpdateDataTableEntry but these both services creates a new entry because the value of the primary key changes too. what is the best solution in this regard should i delete the entry first and then add the new one or how you can see this problem?
currently i set another primary key and just updates the value with this hardcoded primary key.
const serviceName = "AddOrUpdateWaxingCan";
const LOG_PREFIX = me.name + " :: " + serviceName + " :: ";
logger.info(LOG_PREFIX + "Start Service");
let waxingDatatableEntries = Things["QGate.WaxingCan.DT"].GetDataTableEntryCount();
let dataTable = Things["QGate.WaxingCan.DT"].GetDataTableEntries({
maxItems: waxingDatatableEntries
});
let dateNow = Date.now();
// Erstellen eines neuen Eintrags für deine DataTable
let values = Things["QGate.WaxingCan.DT"].CreateValues();
values.chargeExpireDate = chargeExpireDate;
values.picture = picture;
values.chargeNumber = chargeNumber;
values.shiftExpireDate = dateNow * 1000 + me.shiftExpireTime;
values.primary =1;
try {
Things["QGate.WaxingCan.DT"].AddOrUpdateDataTableEntry({values: values});
result = dataTable;
} catch (error) {
logger.error(LOG_PREFIX + "Error updating entry in DataTable: " + error.message);
}
Solved! Go to Solution.
Hi Jamal,
If I'm not wrong, primary key values cannot be updated. It should serve the purpose of a unique record. So immutable.
Additionally the service you invoke works just fine:
AddOrUpdateDataTableEntry Service:
As a workaround I cannot see any solution other than what you have mentioned.
Hi Jamal,
If I'm not wrong, primary key values cannot be updated. It should serve the purpose of a unique record. So immutable.
Additionally the service you invoke works just fine:
AddOrUpdateDataTableEntry Service:
As a workaround I cannot see any solution other than what you have mentioned.