Skip to main content
1-Visitor
January 22, 2021
Solved

How to check 'DoesThingExists' in TWX 9.1 using script

  • January 22, 2021
  • 1 reply
  • 1632 views

Hi Team,

 

I was using TWX 8.3 version earlier which was having below snippet:-

 

var params = {
thingName: thingName /* STRING */
};

// result: BOOLEAN
var result = Resources["PTC.Factory.CommonUtilities"].DoesThingExists(params);

 

But in ThingWorx 9.1, PTC.Factory.CommonUtilities is not available.

 

How would I run my code now?

 

Please provide snippet for ThingWorx 9.1 for checking the existence of Thing in the composer.

 

Thanks in advance.

Best answer by slangley

Hi @ranjank.

 

PTC.Factory.CommonUtilities sounds like ThingWorx Apps.  Do you have Manufacturing or Service Apps installed?

 

As an alternative, you could do something like this:

 

try{​​
result = Things[thingName].name;
}​​
catch (err) {​​
result = "Thing does not exist";
}​​

 

You'll need to pass in the thingName you're looking for.

 

Regards.

 

--Sharon

1 reply

slangleyCommunity ManagerAnswer
Community Manager
January 22, 2021

Hi @ranjank.

 

PTC.Factory.CommonUtilities sounds like ThingWorx Apps.  Do you have Manufacturing or Service Apps installed?

 

As an alternative, you could do something like this:

 

try{​​
result = Things[thingName].name;
}​​
catch (err) {​​
result = "Thing does not exist";
}​​

 

You'll need to pass in the thingName you're looking for.

 

Regards.

 

--Sharon

Community Manager
February 1, 2021

Hi @ranjank.

 

If the previous response answered your question, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon