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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

DataTable entry update service query

MA8731174
14-Alexandrite

DataTable entry update service query

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);
    }

 

 

ACCEPTED SOLUTION

Accepted Solutions
AdamK_93
12-Amethyst
(To:MA8731174)

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:

  • Use the AddOrUpdateDataTableEntry service to update an existing entry in your DataTable.
  • If the primary key value changes, this service will automatically update the corresponding entry.

As a workaround I cannot see any solution other than what you have mentioned. 

View solution in original post

1 REPLY 1
AdamK_93
12-Amethyst
(To:MA8731174)

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:

  • Use the AddOrUpdateDataTableEntry service to update an existing entry in your DataTable.
  • If the primary key value changes, this service will automatically update the corresponding entry.

As a workaround I cannot see any solution other than what you have mentioned. 

Announcements


Top Tags