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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

POST JSON Service- Auto execution challenge

priyank
5-Regular Member

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

1 ACCEPTED SOLUTION

Accepted Solutions
priyank
5-Regular Member
(To:rjanardan)

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.

 

we need to give system permission to Resources. which we are using in our POST JSON script.

var result= Resources["ContentLoaderFunctions"].PostJSON(params);

 

Regards,

Priyank

View solution in original post

11 REPLIES 11

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 ?

priyank
5-Regular Member
(To:vinakumar)

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-

  1. I have checked the Subscription is in enabled state.
  2. Subscription details verified- mapping of property and POST service.
  3. Data changes in related property are verified.
  4. We have configured the property and service in same entity(Thing) also and try but didn’t work.
  5. We have checked the Run type permissions to as enabled for System and Administrator.
  6. 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.
  7. And when we execute Service “A” manually then POST JSON script also got execute automatically.
  8. We have tried loggers in subscription and in POST JSON service but not getting exact root-cause.

 

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?

priyank
5-Regular Member
(To:rjanardan)

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

priyank
5-Regular Member
(To:rjanardan)

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.

priyank
5-Regular Member
(To:priyank)

priyank_0-1588857993831.png

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

priyank
5-Regular Member
(To:rjanardan)

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

 

priyank
5-Regular Member
(To:rjanardan)

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.

 

we need to give system permission to Resources. which we are using in our POST JSON script.

var result= Resources["ContentLoaderFunctions"].PostJSON(params);

 

Regards,

Priyank

Top Tags