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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Using "sourceProperty" variable with Dynamic Subscriptions

MarkCheli
6-Contributor

Using "sourceProperty" variable with Dynamic Subscriptions

Hi All!

Part of my application allows the user to set up their own custom "If [condition] then [action]".  Currently I am taking their condition information and creating an Alert dynamically.  Now I am attempting to apply the action via a subscription that is also created dynamically.  Here's how I create the subscription currently...

var params = {

    propertyName: logicProp,

    eventName: "Alert",

    thingName: undefined,

    serviceName: "SubscriptionActionService"

}

me.AddDynamicSubscription(params);

This works, and the dynamic subscription does trigger the SubscriptionActionService.  However typically with a regular static subscription, you have access to variables from the event information from the alert, e.g. sourceProperty.  As you may imagine since SubscriptionActionService is abstract, it needs to be passed some information in order to execute the correct service.

Here's what I have currently for SubscriptionActionService...

var serviceName = me.logic[sourceProperty].actionService;

me[serviceName]();


Logic is a JSON property which contains a list of which services should be executed based on which property is triggering the alert.  The problem is that "sourceProperty" does not exist on dynamic subscriptions (based on my current knowledge).  I have also tried referencing the property via eventData.sourceProperty as well.  Is there another way for me to reference this information?  Alternatively, is there another way to dynamically execute a service/subscription as the result of an alert?


TLDR:  How can you access information about the alert event from a dynamic subscription?

1 REPLY 1
PaiChung
22-Sapphire I
(To:MarkCheli)

have you tried just 'source' ?

Top Tags