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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Determine trigger origin

sdejager
7-Bedrock

Determine trigger origin

Hello,

Is there an easy way to determine the origin of a trigger.
For example:
A mashup with 2 buttons triggering the same service.

screencapture-dev-online-indeff-Thingworx-Composer-index-html-1483537269047.png

Kind regards,

Simon

13 REPLIES 13

Don't think so, but you may call Add Service twice and add a static parameter to the Add service which tells which origin it's.

The problem with that setup is that you can not bind the output of both services to one numericvalue

Yup you are right

Doing some expressions evaluation and hidden checkboxes you may reach what you want, but won't be easy neither to explain here I'm sorry.

What you are trying to accomplish? maybe another way.

That is what we are doing now
but it gets easily confusing and messy, so I was hoping for an easier solution.

Yes I know I have couple of them...

jamesm1
12-Amethyst
(To:sdejager)

Button widgets have a ContextId property that you can set to a custom value for each button, i.e. button1 and button2. You can then pass this in to the service and do a check as to which context ID was being passed.

Hi James,

This doesn't helps on what Simon want's to accomplish.

Carles

jamesm1
12-Amethyst
(To:CarlesColl)

Ah, you're right -- you can't double bind the parameter with both context ids... in my head I was thinking you could pass it like a message with the clicked event of the button.

This may be a little wonky/messy, but one way you can do it is:

  1. Create a session variable called contextId
  2. Add SetGlobalSessionStringValue from CurrentSessionInfo to the mashup twice
  3. Tie each button clicked event to each of the separate SetGlobalSessionStringValue with each contextId as the value param, and set the name param to context id, and each button clicked event to trigger setting the session variable
  4. Add GetGlobalSessionValues service from CurrentSessionInfo and have it run on the service invoke complete event from the two SetGlobalSessionStringValue services
  5. Put the result contextId  from the GetGlobalSessionValues as the input parameter of the main service you want to call, and call it on ServiceInvokeComplete of the GetGlobalSessionValues.

Then continue as I had posted above. This same result might be easier the way you suggested earlier, however.

Edit: Actually, you could simplify this on the mashup end  by calling the GetGlobalSessionValues  in the main service you want to call, instead of on the mashup. This way you could just bind ServiceInvokeComplete of each of the SetGlobalSession... services to the main service you want to call, and get the current contextId in that service before doing your if or switch statement to see which one is the current clicked property. Note that I wouldn't use the contextId from the session tab in the mashup, because it may not get updated when you call the  SetGlobalSession.. services.

ttielebein
14-Alexandrite
(To:jamesm1)

This is the right way to do this. Call SetGlobalSessionString Value and use a different value for each button, e.g. "Button1" versus "Button2". Then, trigger the next service using ServiceInvokeCompleted from this session variable one. In the service you call, immediately GetGlobalSessionVariables and determine which button was clicked, and proceed from there.

Simon de Jager​ I have used this method before successfully to do what you are trying to do. I hope this helps!

PaiChung
22-Sapphire I
(To:jamesm1)

I'm not sure if you can actually pass that Context ID from a Widget.

If that is possible, you can use an Expression widget to now make it all a single input.

jamesm1
12-Amethyst
(To:PaiChung)

The context ID on the button widget is bindable in both directions -- but I couldn't think of how to wire it into a single expression, because you could add two parameters but still wouldn't know which one was pressed when the expression is evaluated?

PaiChung
22-Sapphire I
(To:jamesm1)

Do an additional output from the expression widget to a textbox that is wired back as an input that is the tester value (you can be a source to many and expression can take in many inputs so this will not be too challenging)

qngo
12-Amethyst
(To:sdejager)

You can create a new service or two new services and add it/them between the click event and the service Add, to log the origin of the trigger (logger.info, etc) :

+1 _ Clicked --> LogButton1 _ Service invoke completed --> Add

+2 _ Clicked --> LogButton2 _ Service invoke completed --> Add

Announcements


Top Tags