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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Set Timestamp on button click

Chao123
12-Amethyst

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

Accepted Solutions
Chao123
12-Amethyst
(To:slangley)

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

View solution in original post

2 REPLIES 2
slangley
23-Emerald II
(To:Chao123)

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

Chao123
12-Amethyst
(To:slangley)

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


Top Tags