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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

How to store the state of variable in thingworx functions

Jamal8548
11-Garnet

How to store the state of variable in thingworx functions

Is there any way that i can store the state of this parameter in expression. I dont have anything to bind it from my mashup. So in the screenshot you can see that i have bool which has default value true and i just want it to change every time i use this function. For example I change the state to false then again next time i evaluate i turn it into true

 

Jamal8548_0-1712292862465.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @RadekIOT  @Rocko , Thank you both of you. Its working now. The problem was that when i uncomment the console.log it does not work... I just commented it out and now everything is working perfectly fine! Sometimes Thingworx is a bit different haha..

Jamal8548_0-1712302190297.png

 

View solution in original post

10 REPLIES 10
Rocko
17-Peridot
(To:Jamal8548)

To store and reuse the computed value, you can try

a) a Checkbox you make invisible

b) a Mashup parameter

c) a Session variable

Jamal8548
11-Garnet
(To:Rocko)

I create an expression 

Jamal8548_0-1712298747344.png

 

Expression detials

 

Jamal8548_1-1712298786634.png

I have created a mashup parameter named status. Its a checkbox and i have selected it with true and i change it everytime i run this expression so i change it to true and false

 

Jamal8548_2-1712298915348.png

 

mashup parameter

Jamal8548_3-1712298934719.png

 

Now the problem is i get in console.log no value neither true nor false. it shows me empty space in console.log. can you see whats an issue?

Rocko
17-Peridot
(To:Jamal8548)

Maybe try to assign a value when opening the mashup first to debug. You can also log something on the event of statusChanged which should be there on the mashup.

It can be it does not work with mashup parameters.  Options a) and c) are sure shots though.

Jamal8548
11-Garnet
(To:Rocko)

My bindings are below:-

 

Jamal8548_0-1712299844336.png

I have a checkbox with state by default i have selected true.

Jamal8548_1-1712299924712.png

 

Still it does not work and not even returning anything but on mashup it needs to fill the checkbox but it is not even filled as by default i have selected it true.

Jamal8548_2-1712299995452.png

 

what can be the cause? 

If i select the checkbox manually on mashup and then run the expression it returns true and again true if i execute again. its not changing to false true .....

 

 

RadekIOT
4-Participant
(To:Jamal8548)

Try this setting in Expression

RadekIOT_0-1712300619082.png

 

RadekIOT
Rocko
17-Peridot
(To:RadekIOT)

I would also extend the expression to account for undefined value (e.g. assign false then).

I tried and now the output is coming but the topic here is i want to switch it to true and false and again on every execution the state will change to true and then false. right now its just making it false false false. i want to switch the state because i have used EVENT ROUTER and its input i want to change everytime to refresh something. if it stays like this it will not work.

Hi @RadekIOT  @Rocko , Thank you both of you. Its working now. The problem was that when i uncomment the console.log it does not work... I just commented it out and now everything is working perfectly fine! Sometimes Thingworx is a bit different haha..

Jamal8548_0-1712302190297.png

 

Rocko
17-Peridot
(To:Jamal8548)

Interesting, good to know. I guess this is why the recommendation is to use TW.log.debug for logging. https://support.ptc.com/help/thingworx/platform/r9/en/#page/ThingWorx/Help/Mashup_Builder/Migration/BestPracticesExpressions.html

I guess the console.log somehow messes with the Output variable.

 

Note that the expression also has a Changed event, so maybe you don't need another event router.

Jamal8548
11-Garnet
(To:Rocko)

Thanks for recommendation.

    I am sending the result into another mashup and there i am getting this true false to refresh the mashup via mashup parameter thats why i cannot use changed event in this mashup directly because i want it into another mashup not in the same mashup where i have implemented this EXPRESSION.

Top Tags