I must be not looking in the right place because I can not find a service that checks if I thing exists? I see the "isBound" service but it seems to not be very accurate- always returning false?
You may use try/catch snippet and define the exception for the error. For example, you may use an alternative service that runs on the thingname, but if it doesn't exist, then the catch will define the error.
I have used below code to find and delete timer if exits in my application
try {
var content = {
type: "Thing" /* STRING */,
nameMask: "ThingName",
tags: undefined /* TAGS */
};
var params = {
headers: undefined /* JSON */,
content: content /* JSON */,
url: 'ThingWorxURL/Resources/EntityServices/Services/GetEntityList/',
username: "Username",
password: "Password",
ignoreSSLErrors: true,
timeout: 30
};
var searchResult = Resources["ContentLoaderFunctions"].PostJSON(params);
if(searchResult.rows.length > 0)
{
// delete thing
content = {
name: searchResult.rows[0].name /* STRING */
};
params = {
headers: undefined /* JSON */,
content: content /* JSON */,
url: 'ThingWorxURL/Resources/EntityServices/Services/DeleteThing/',
username: "Username",
password: "Password",
ignoreSSLErrors: true,
timeout: 30
};
Resources["ContentLoaderFunctions"].PostJSON(params);
}
}
catch(err) {
logger.warn("Unable to delete GetAlarmResources_Timer "+err);
}