4 Replies Latest reply on Jun 4, 2015 3:31 PM by bshang

    Attribute value update

    ArunaNamadev

      I am unable to update value to AFAttribute, I have used the following method to update the value. But the value is not getting updated.

      Data Reference name is String Builder

       

      AFAttribute attr = objElement.Attributes["PREPROCESSHUMIDITY"];

        OSIsoft.AF.UnitsOfMeasure.UOM uom= afServer.UOMDatabase.UOMs["percent"];

      AFValue value = new AFValue(objElement.Attributes["PREPROCESSHUMIDITY"], i, AFTime.Parse("T"), uom, AFValueStatus.Good);

      attr.SetValue(value+"%",uom);

        • Re: Attribute value update
          bshang

          Hi Aruna,

           

          I do not believe it's possible to write via a String Builder DR. What would be its system of record for example? We can check if the SetValue call is supported by looking at the AFDataReference.SupportedMethods property and AFDataReference.SupportedDataMethods property for the String Builder DR (accessed via SupportedMethods property for the String Builder attribute for example).

           

          For String Builder DR, AFDataReference.SupportedMethods does not include SetValue and AFDataReference.SupportedDataMethods does not include UpdateValue.

           

          The String Builder DR is mainly used for metadata or formatting output of another attribute.

           

          For the PREPROCESSHUMIDITY attribute, it seems like it would be a "process data" DR, such as PI Point DR, which would of course accept writes. Is there a specific use case here for writing to the String Builder DR? If it's for formatting, I would recommend writing to a PI Point DR, and then reference the PI Point DR attribute in the String Builder DR attribute to format the output, using a config string such as "Format('PIPointDR1',"%3.2f");%;" for the string builder attribute.

            • Re: Attribute value update
              ArunaNamadev

              Hi ,

               

              I want to update a  numeric value say for example 10 % for that attribute.

              later in future i want it to be from PI point tag.

              how to set the value using attribute.setvalue?

                • Re: Attribute value update
                  Rhys Kirk

                  As Barry Shang mentions above, not sure why you're writing to a String Builder Attribute. You'll be better off in the interim writing to an Attribute configured with no Data Reference if you don't have a PI Point to write to. Also, the Windows Identity you are writing to the Attribute with will need to have the "Write Data" permission on the host Element.

                  • Re: Attribute value update
                    bshang

                    Hi Aruna,

                     

                    As Rhys mentioned, you can write to an Attribute without a Data Reference, as shown below

                    In the code, you can do

                     

                    attr.SetValue(value);

                     

                    Because I've configured the UOM above as "percent", there is no need to use String Builder to simply add the UOM (%) (the same applies for PI Point DRs); it will be appended to the number (i.e. 11 %).