Skip to main content
1-Visitor
December 8, 2015
Solved

UpdatePropertyValues service

  • December 8, 2015
  • 4 replies
  • 7598 views

Hi there

I've tried everything I could think of but I could not correctly call the UpdatePropertyValues function.

What Infotable is it waiting for ?

I need it for updating logged properties simultaneously, to not create a new log for each one.

if you have another solution for this problem, i'll gladly hear it, but I'd like an answer to the question because it has been bothering me for months.

Thank you.

    Best answer by qn_01

    Hi,

    Here is how I use this service:

    var params = {

          infoTableName: "UpdatePropertiesInfoTableTMP" /* STRING */,

          dataShapeName: "NamedVTQ" /* DATASHAPENAME */

    };

    var updateValues = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

    var time = new Date();

    updateValues.AddRow({'time': time, 'name': 'Property1Name', 'quality': 'GOOD', 'value': property1Value});

    updateValues.AddRow({'time': time, 'name': 'Property2Name', 'quality': 'GOOD', 'value': property2Value});

    ...

    me.UpdatePropertyValues({values: updateValues});

    4 replies

    1-Visitor
    December 8, 2015

    Francky,

    How are you calling the service?

    James

    fblondy1-VisitorAuthor
    1-Visitor
    December 8, 2015

    In many different ways.

    var params = {

        values: undefined /* INFOTABLE */ <-------- THIS is the problem, I've tried to put everything I could think of (only and always Infotables though)

    };

    me.UpdatePropertyValues(params);

    1-Visitor
    December 8, 2015

    How are you getting the updated values into the infotable? Are you calling the REST API?

    qn_011-VisitorAnswer
    1-Visitor
    December 8, 2015

    Hi,

    Here is how I use this service:

    var params = {

          infoTableName: "UpdatePropertiesInfoTableTMP" /* STRING */,

          dataShapeName: "NamedVTQ" /* DATASHAPENAME */

    };

    var updateValues = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

    var time = new Date();

    updateValues.AddRow({'time': time, 'name': 'Property1Name', 'quality': 'GOOD', 'value': property1Value});

    updateValues.AddRow({'time': time, 'name': 'Property2Name', 'quality': 'GOOD', 'value': property2Value});

    ...

    me.UpdatePropertyValues({values: updateValues});

    1-Visitor
    December 8, 2015

    QD beat me to it! See below for my alternative (and verbose!) update call:

    // Create a new blank infotable for passing into the 'update' service

    var params = {

        infoTableName: "MyUpdateTable" /* STRING */

    };

    // result: INFOTABLE

    var myUpdate = Resources["InfoTableFunctions"].CreateInfoTable(params);

    // add the name field to the datashape for the update table

    // this will hold the name of the property to update

    var nameField = new Object();

    nameField.name = "name";

    nameField.baseType = 'STRING';

    myUpdate.AddField(nameField);

    // add the value field to the datashape for the update table

    // this will hold the value of the property to update

    var valueField = new Object();

    valueField.name = "value";

    valueField.baseType = 'STRING';

    myUpdate.AddField(valueField);

    // add the row that contains the update for temperature

    var updateRow = new Object();

    updateRow.name = 'temperature'; // << your actual property name here

    updateRow.value = 32.0 // << your new value for that property here

    // add the temperature row new value to the infotable

    myUpdate.AddRow(updateRow);

    var params = {

        values: myUpdate /* INFOTABLE */

    };

    // Finally, update my thing with the properties in the table

    me.UpdatePropertyValues(params);

    1-Visitor
    April 1, 2016

    The problem with this method is that the "value" of "updateRow" must be of a type which could be converted to STRING.

    fblondy1-VisitorAuthor
    1-Visitor
    December 8, 2015

    I'll be damned, it works.

    I don't understand what was my mistake. I didn't try like James, but tried something similar to what QD did, but with a custom datashape containing name and value as Strings and it didnt work.

    I now tried with a dynamic DS (like James) and it worked (probably the only way I had not tried yet)

    Thanks