4 Replies Latest reply on Sep 3, 2018 3:26 AM by rfox

    AF Element.Refresh using AFSDK

    CarolPL

      I have an objective to ensure that all queries I make to
      AFAttributes in any Element always return the latest result (checked in items
      only) regardless of whether its value or formula has changed.

       

      The simplest solution appears to use the AFElement refresh
      method before I get a pointer to the Attribute I need once the Element has been
      found as below                     
      AFElement Elem = (AFElement) AFObject.FindObject(<Server\Element
      path>);                       
      Elem.Refresh();  // Ensure Element is current                   
      AFAttribute Attr = AFAttribute.FindAttribute(<Required attribute name,
      AFObject.FindObject((<Server\Element path>));

      Does anyone know the impact of this ie if no changes then
      minor performance or a full refresh is done regardless.

      This may be done many times a second, but it appears to work
      with minor performance impact even when changes are required, the only other
      way I can think of is to use the notification events ie the AFElement.Changed
      event

      All comments welcome

        • Re: AF Element.Refresh using AFSDK
          Roger Palmen

          I think impact depends on scale. For just one Element i would not worry, but for thousands...

          • Re: AF Element.Refresh using AFSDK
            Dan Fishman

            When you call refresh, if there are no changes, then you not be reloading the element, but you still will have the expense of a network call.

            Instead of the AFElement.Changed event, you might have better performance using FindChangedItems method. You could get all of the objects that changes, and only refresh/load the ones you are interested in by examining the GUID.

             

              Do you know which elements you will be querying or do you query different elements each time?

            • Re: AF Element.Refresh using AFSDK
              CarolPL

              Thanks for the replies.

               

              The number of elements to
              refresh is quite low < 100 but any of them may be updated any time. Although
              95% of the time there will be no changes.

              Each query is different, some
              queries to AF Attributes, some to collected tags as part of a formula/analysis
              and some direct to archive servers.

              The refresh forms a prelude to a
              data fetch that is performed over the requested time range.

               

              Thanks - Might be worth
              exploring the Find ChangedItems which will run in the core code and force a
              refresh if the requested Attribute forms part of a changed element, does seem
              rather wasteful performing a refresh if there are no changes.