1 Reply Latest reply on Nov 15, 2016 6:51 PM by pmartin

    Set AF attribute with AFSDK code

    mikespath

      Hello Folks:

      I know this is possible to do but I'm trying to find documentation and / or example code by which to do. I've created an AF template for a data source (vessel) and I have an instance of this (vessel3)

      I created attributes (for example) DO_H to hold a value that is used in the notification trigger when it is violated.

      I'm looking for help on how to set the Attribute vessel3.DO_H in code.

      I the help I see    AFAttribute.SetValue Method (Object, UOM) but not sure if that is what I would use.

      Any guidance appreciated as I'm new to AF.

      Thanks

        • Re: Set AF attribute with AFSDK code
          pmartin

          Hi Mike,

           

          You have the right idea.  You can set this attribute value using the SetValue method.

          This method has a number of overloads (as you have probably noticed in the help file) but probably the easiest one to use is the SetValue( AFValue newValue ) overload.

           

          The first order of business is getting a handle for the attribute.  In this case you have a known path to your attribute so you can do something like:

          AFAttribute a = AFAttribute.FindAttribute(@"\\<server-name>\<database name>\One Hill Solutions\Proplus\Vessel3|DO_H",null);
          

           

          If you wanted a more general approach, you can look in to searches using the FindElementAttributes method.

           

          Once we have the attribute, we can construct an AFValue object.  We'll use the simplest constructor that we can still specify a value, AFValue(object). Finally, we'll set the value of our attribute to this AFValue.

          AFValue v = new AFValue(50);
          a.SetValue(v);
          

           

          If you want to specify a Unit of Measure (UOM), that's possible with another overload.  It doesn't look like that attribute is currently using one, but if you'd like more information on the subject, I'd be happy to help.

          2 of 2 people found this helpful