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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

CalculateStatus does not run immediately after being called

Willie
16-Pearl

CalculateStatus does not run immediately after being called

On my asset detail page, I have a mute button (toggle) to "Disable" the asset Thing.  When this button is toggled from "OFF" to "ON", it mutes (disables) the asset Thing. 

 

Thingworx - 2020-04-30 - muteButton-2.PNG.jpg

The code for this process is shown below:

 

 

try {
if (Things[SerialNumber].MuteStatus === false) {

Things[SerialNumber].MuteStatus = true;
Things[SerialNumber].MuteDate = new Date();
Things[SerialNumber].AssetStatus = 6;
Things[SerialNumber].CalculateStatus();

logger.info(me.name + ": muteAsset: isReporting: " + Things[SerialNumber].isReporting.toString() + " reportingLastChange: " + Things[SerialNumber].reportingLastChange);
logger.info(me.name + ": muteAsset: MuteStatus: " + Things[SerialNumber].MuteStatus.toString() + " AssetStatus: " + Things[SerialNumber].AssetStatus + " status: " + Things[SerialNumber].status + " isEnabled: " + Things[SerialNumber].IsEnabled());
Things[SerialNumber].DisableThing();
logger.info(me.name + ": muteAsset: isReporting: " + Things[SerialNumber].isReporting.toString() + " reportingLastChange: " + Things[SerialNumber].reportingLastChange + " isEnabled: " + Things[SerialNumber].IsEnabled());
}
} catch (err) {
logger.error("muteAsset: " + err.lineNumber + ": " + err);
}

 

 

For some reason, DisableThing( ) completes execution before CalculateStatus( ).  I need CalculateStatus( ) to complete execution before DisableThing( ), because I need it to change status to "Muted" before it gets disabled.  I know DisableThing( ) completes execution before CalculateStatus( ), because I saw in the script log that it tried to run line 7 (CaculateStaus) after the asset Thing was disabled.  Please see the screenshot below:

Thingworx - 2020-04-23 - muteAsset service CalculateStatus error.PNG

It seems that CalculateStatus( ) executes at least 7 seconds after the muteAsset( ) service was called.  How can I get CalculateStatus( ) to execute before DisableThing( )?

1 REPLY 1
abhkumar
13-Aquamarine
(To:Willie)

HI  @Willie,

 

Could you please mention which OOTB services have you customized for mute status calculation and which other services of Thing Shape PTC.SCA.SCO.StatusThingShape  have you customized.

 

Additionally, it required to investigate  into the snippets you have written. Do you mind opening a support case for it.

 

Thanks

Abhishek

Top Tags