Skip to main content
Jul 15, 2019 6:55 PM UTC
Solved

Set Timestamp on button click

I have a table table with a field called AcknowledgeTStamp. I need it to fill be filled with the current date/time on the click of a button and then set to null with the click of another button. I tried the code below for my acknowledge service on my thing. I can't seem to figure it out. Any thoughts? 

var createITParams = { infoTableName : "", dataShapeName : "" };

var properties = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(createITParams);

// create a row with data
var row = new Object();
row.name = "AcknowledgeTStamp"; // name of your property
row.value = 5; // desired value
row.time = new Date(); // you can set any timestamp you need - important when using ValueStreams to log

properties.AddRow(row);

Things[""].UpdatePropertyValues({ values: properties });
Chao123Answer
Jul 18, 2019 11:29 AM UTC

My updated code worked out below. I used the updatedatatableentry snippet on the Entities tab of the service.

if(!warehouseID) {
	throw "invalid warehouseID";
} 
if (!DMRNumber) {
 throw "invalid DMR";
}


if(!ackusername) {
 
	// result: STRING
	ackusername = Resources["CurrentSessionInfo"].GetCurrentUser();
} 


var values = Things["MBCI.JAIN.DataTable.DMRAlert.DMRData"].CreateValues();

var ackTstamp = new Date();

values.AcknowledgedTStamp = ackTstamp; //DATETIME
values.WarehouseID = warehouseID; //STRING [Primary Key]
values.AcknowledgedUsername = ackusername; //STRING
values.DMRNumber = DMRNumber; //LONG [Primary Key]
values.AcknowledgedFlag = true; //BOOLEAN


// no return
Things["MBCI.JAIN.DataTable.DMRAlert.DMRData"].UpdateDataTableEntry({values: values});

2 replies

Jul 17, 2019 7:09 PM UTC

Hi @Chao123.

 

The biggest problem we see is that there's no result coming from the service (assuming the snippet you provided is complete).    Also, did you scrub the code before providing it?  We weren't sure if the infoTableName and dataShapeName were scrubbed or if that is another issue.

 

It would help if you can provide further details of your use case so we can guide you effectively.

 

Regards.

 

--Sharon

Chao123AuthorAnswer
Jul 18, 2019 11:29 AM UTC

My updated code worked out below. I used the updatedatatableentry snippet on the Entities tab of the service.

if(!warehouseID) {
	throw "invalid warehouseID";
} 
if (!DMRNumber) {
 throw "invalid DMR";
}


if(!ackusername) {
 
	// result: STRING
	ackusername = Resources["CurrentSessionInfo"].GetCurrentUser();
} 


var values = Things["MBCI.JAIN.DataTable.DMRAlert.DMRData"].CreateValues();

var ackTstamp = new Date();

values.AcknowledgedTStamp = ackTstamp; //DATETIME
values.WarehouseID = warehouseID; //STRING [Primary Key]
values.AcknowledgedUsername = ackusername; //STRING
values.DMRNumber = DMRNumber; //LONG [Primary Key]
values.AcknowledgedFlag = true; //BOOLEAN


// no return
Things["MBCI.JAIN.DataTable.DMRAlert.DMRData"].UpdateDataTableEntry({values: values});