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

Creating deleting entities programatically in Thingworx

Creating deleting entities programatically in Thingworx

At present, when creating/deleting any entity (Things, Valuestream etc.) programatically through CreateThing service does not return anything; which means the service is non-blocking. Maybe the actual creation of entity happens in some different thread. So if we are creating Things programatically in a loop, all things gets created in parallel without actually knowing if the first thing is created and committed to DB before creating the second thing.

This leads sometimes to getting errors of model access provider.

So if the Create/Delete thing returns something (maybe true false or thing Id sort), it would be easier to proceed and also it would help in preventing creation of Ghost Entities


If a service does not return anything, it does not mean the service is non-blocking. It might be that the service still runs synchronous, but it simply chooses not to return an output.

We would need to make sure that the actual code in the service is optimized for large batch things creation. Do you have a case that displays the behavior you mentioned (model access provider errors) ?


Hi Vladimir,

My only intention of saying that these types of services should be returnable and blocking, is because I am facing such issues of Model access Provider/Data access Provider in my application, for which I am already in touch with PTC, through e-support portal. Moreover these types of errors have huge impact on big solutions, as even we have to change quite a lots of code in our existing solution. Also these types of errors are moreover related to Data Base that we choose, so it is difficult to architect and predict such problems.

In fact I was also wondering, why is it so, that, Thingstart subscription is invoked even before the Thing is properly committed to DB.

Moreover if we are also consider the case of batch of large thing creation, it happens so that unless the service which is creating the large batch of things, exists, the created Things are not committed to DB. So if we try to do anything in Thingstart (like creating and setting the valuestream, or setting the description) it will give these errors. This behaviour is observed in Thingworx 8.4 prominently.


Thanks @amittal1 for creating this idea we face the same issues here. Have you already some news when this will be fixed?


Hi @aschultheiss  Can you please open a case to Tech Support if you encountered this kind of issue? From what I can see this sounds like a bug and I believe the problem must be understood and replicated. What I'm saying is that before treating it as an enhancement we need to make sure it's not a bug - ideally we can solve this in a more proper way.

First of all, thank you for appreciating this idea.
Regarding this I have no news if PTC has any plans to improve this aspect
in the future. However, there is one workaround suggested by PTC, which I
I am sharing the code snippet below -

*var params = { name: /* STRING */, description:
description> /* STRING */, thingTemplateName: /*
THINGTEMPLATENAME */, tags: /* TAGS */ };// no returntry{
Resources["EntityServices"].CreateThing(params); var MAX_ATTEMPTS = 1000;
var searchResult =
Resources["SearchFunctions"].SearchThings({searchExpression: /*
STRING */}); while ((searchResult.thingResults.length === 0) &&
(MAX_ATTEMPTS > 0)) //added While and consecutive if Section; AM -
20June2019 { logger.debug("Inside While for searching the commit,
MAX_ATTEMPTS: " + MAX_ATTEMPTS); searchResult =
Resources["SearchFunctions"].SearchThings(params); --MAX_ATTEMPTS;
pause(1000); } logger.debug("Exiting While for searching the commit,
MAX_ATTEMPTS: " + MAX_ATTEMPTS); if (searchResult.thingResults.length ===
0) { logger.error("Error : Thing [" + + "] not found in
database even after 1000 seconds"); }}catch(err){
//Resources["EntityServices"].DeleteThing({name: /*
THINGNAME */}); logger.debug("Unable to create entity " + + "
Error Is: " + String(err));}*

Basically according to PTC whenever we create any "thing" it might be
possible that it is created but it is not committed in DB. To resolve this
they suggest to use the search function.
You can write this 'customCreateEntity' (service) code and have the return
to this service as per your need.
Please let me know in case you have any doubts.

Aditya Mittal
Community Manager
Status changed to: No Plans to Implement

Thank you. But no plans to implement at this time.