Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hi Team,
May i ask your advice on POST JSON script in Thingworx.
I am facing a challenge to auto trigger the POST JSON script. My POST JSON script running very well when i execute it manually but it is not working with auto trigger.
I have connected it's execution with one of the property data change.
Even i have tried subscription- data change option and tag with the POST JSON script. But its not working. I have checked data is getting change in property.
Please suggest.
Thanks & regards,
Priyank
Solved! Go to Solution.
Hello Janardan,
Thank you so much for all your support!
We have resolved the issue by providing the resources entity to System user as visbility and run mode.
var result= Resources["ContentLoaderFunctions"].PostJSON(params);
Regards,
Priyank
Hi ,
What exactly the issue you are facing ? Did you check your subscription code is triggered on data change event ?. You can check this by simply putting some logger statements at the start of subscription code. Also , would you please make sure subscription which you had written is marked enabled ?
Hi,
Please find below the issue details and my testing so far-
I would like to get suggession from you..
Issue details- POST JSON service is mapped with one of the Subscription based on data change in respective property for automatic execution. But POST JSON service is not getting execute even on data changed in property.
But when we execute the POST JSON script manually, it successfully run.
Checked points so far-
Thanks..
I am assuming your subscription is listening to DataChange event of let's say Property1 and then setting JSON value to a JSON property Property2.
Is there any error in the logs?
You have added log messages. Are these getting written i.e. is the subscription fired at all?
Instead of PostJSON could you try setting a simple property to a hard coded value in the subscription?
Thanks Janardan for reply,
I have passed all values in POST JSON services as hardcoded and used subscription to trigger the POST service based on Property change.
I have write the Logger in subscription and in POST service. please found below error-
Few error are like-
TypeError: Cannot call method "PostJSON" of null (MFM_TR01_TEST#42)]
:- MFM_TR01_TEST is POST JSON service.
Subscription error is-
Error Executing Event Handler 'X' for event Type.Thing:Entity."Y":Event.DataChange:Property."Z"
X- Logger name in subscription
Y- Thing name
z- Property name
It seems PostJSON is being called with null.
Assuming that you have ensured it is not being called using null, could you please add a log message before and after the PostJSON call and check the logs?
What we want to check is whether this subscription is somehow being triggered twice(the second time with null).
Hi Janardan,
yes i have tried but same above mentioned error.
case is- I am subscribing the MQTT topics in property in MQTT thing and based on that topic property change, i need to execute the POST JSON script.
So i called the POST JSON script in Subscription and input is selected a MQTT Topic property-data change. So whenever the new MQTT message will subscribe , the POST JSON script to be execute.
for testing, i have wrote all input value hardcoded in POST JSON.
But it is not working.
May i know how to correct if subscription is executing twice, even property change once only.
Please find above snap of error logs.
The issue is probably the one described in this article. System user is not having visibility to ThingworxPersistenceProvider
Hi Janardan,
Thank you so much..
I have added my project into visibility of Thingworxpersistanceprovider but i am not sure how to add system user under visibility of Thingworxpersistanceprovider.
Meanwhile, in logger by try and catch method- i got the below error. But i am not sure why the java error is coming because i am using defined POST json script available in content loader and it is running well when i execute it manually.
Error in: "Thingname"."POST JSON Service" javascript service
Regard,
Priyank
By default, all users are members of Everyone organization including System user. Alternatively, you could add System user to your own Organization. Then provide this Organization visibility to ThingworxPersistenceProvider.
You could use below snippet to see the Organizations of System user.
var result = Users["System"].GetOrganizations();
Hello Janardan,
Thank you so much for all your support!
We have resolved the issue by providing the resources entity to System user as visbility and run mode.
var result= Resources["ContentLoaderFunctions"].PostJSON(params);
Regards,
Priyank