Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hi,
I have a DATETIME property named 'Born' which records the time at which a remote thing is created on the server. I create the things via a service I wrote, which monitors for unbound devices and then creates an instance from a template I created. Immediately after the thing is created I set this property to the current time. However, I have noticed that this property updates to a later time periodically, even though I don't have any other service which sets this parameter. At first I thought there might be some old service that was being called that assigned a new time value to it. To check this I exported all my templates to an xml file on my pc and then searched for occurrences of the property 'Born'. Aside from the definition of the property in the template it only occurred in one other place, my create service.
var unboundPrinterTable = Resources["DeviceFunctions"].GetUnboundIdentifiers(maxNum);
var numPrinters = unboundPrinterTable.rows.length;
for (var x = 0; x < numPrinters; x++)
{
var newPrinter = unboundPrinterTable.rows
thingObj = Things[newPrinter.name] ;
//check to make sure it doesn't exist already
if(thingObj)
{
logger.debug(newPrinter.name+" exist - abort creation!");
}
else
{
//Create the printer thing here
var newName = newPrinter.name ;
try
{
var thingParams = {
name: newName /* STRING */,
description: "auto generated XXXX Remote Printer thing created by SystemMonitor" /* STRING */,
thingTemplateName: "XXXRemotePrinterTemplate" /* THINGTEMPLATENAME */,
tags: "Applications:LinxCloud v1.0" /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(thingParams);
var newThing = Things[newName] ;
newThing.EnableThing();
newThing.RestartThing();
//var ident = {identifier: params.name /* STRING */};
var ident = {identifier: newName /* STRING */};
newThing.SetIdentifier(ident);
newThing.DisplayName = newName ;
var now = new Date();
newThing.Born = now ;
//set up remote bindings to parameters on the edge server
newThing.CreateRemoteBindings();
newThing.RestartThing();
}
catch(err)
{
logger.error("Create new printer fail - err = "+err);
}
Although most of my things were created months ago the 'Born' value on those things reads as times from earlier today. does anyone have any idea what might be going on?
thanks. Also a bit odd that all the devices appear have the same updated time
Thanks
Kieron
I've since discovered that the 'Born' DATETIME property is getting updated to the current time on my things, every time I modify the template on which the things are based.
i.e. If I add a new property to the template the 'Born' property on my things get updated to the time I save the changes to the template.
Is there any way to stop this happening, All the other properties that are remotely bound do not change. Is there some setting that I should have used?
K
It are declared as persistent?
Just one side note (not related to your problem), you should do explicit casts when dealing with TW objects:
if (thingObj) --> Should be --> if (thingObj!=null)
check my document: https://community.thingworx.com/docs/DOC-4004?et=watches.email.document_comment#comment-4469
Best Regards,
Hi Carles, thanks for replying. Yes it is declared as persistent.
p.s. thanks for the javascript tip, will use that from now on.
Then I don't know, It seems a bug, I sounds to me that there was this kind of bug on a TW version. Had you checked the release notes of TW Versions
Just to mention, this was reported in TW-31694 and is currently in the backlog.
var mytimestamp = new Date().getTime();
https://www.ptc.com/en/support/article?n=CS275043