POST JSON Service- Auto execution challenge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
POST JSON Service- Auto execution challenge
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Tags:
- 8.5
- ThingWorx 8.5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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-
- I have checked the Subscription is in enabled state.
- Subscription details verified- mapping of property and POST service.
- Data changes in related property are verified.
- We have configured the property and service in same entity(Thing) also and try but didn’t work.
- We have checked the Run type permissions to as enabled for System and Administrator.
- We have tried to link the POST JSON service’s execution in another service(example Service “A”) and we bind the related property with service “A” using subscription. So whenever the property changed, the Service ”A” executed automatically but POST JSON service didn’t execute.
- And when we execute Service “A” manually then POST JSON script also got execute automatically.
- We have tried loggers in subscription and in POST JSON service but not getting exact root-cause.
Thanks..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Please find above snap of error logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
The issue is probably the one described in this article. System user is not having visibility to ThingworxPersistenceProvider
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Tags:
- 8.5
- ThingWorx 8.5
