1 Reply Latest reply on Aug 22, 2016 2:15 PM by pchung RSS
    mcheli Explorer

    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?