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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Service to see if Thing Exists

jmay1
5-Regular Member

Service to see if Thing Exists

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?

2 REPLIES 2
posipova
20-Turquoise
(To:jmay1)

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

}

Top Tags