4 Replies Latest reply on Jan 4, 2018 8:53 PM by bbregenzer

    Create button to do an element Search


      Hi ,


      What im trying to do is display all the sensors that have status = offline. Im able to display these sensors using the Pi Builder initially, but when i click on Refresh it only updates the current sensors that are on the excel sheet i would like it to display any new sensors that have a status = offline

        • Re: Create button to do an element Search

          Hi Alan,


          You can write custom application using AF SDK to list out sensors which are offline.

          1. PISystems myPISystems = new PISystems();
          2. PISystem myPISystem = myPISystems.DefaultPISystem;
          3. AFDatabase database = myPISystem.Databases["AFDatabaseName"];
          4. AFElementTemplate template = database.ElementTemplates["AFTemplateName"];
          5. AFSearchToken templateToken = new AFSearchToken(AFSearchFilter.Template, AFSearchOperator.Equal, template.GetPath()); 
          6. AFSearchToken valueToken = new AFSearchToken(AFSearchFilter.Value, AFSearchOperator.Equal, "Offline", template.AttributeTemplates["Status"].GetPath()); 
          7. AFElementSearch elementSearch = new AFElementSearch(database, "FindSubTreeElements", new[] { templateToken, valueToken }); 
          8. elementSearch.CacheTimeout = TimeSpan.FromMinutes(10); // Opt in to server-side caching 
          10. IEnumerable<AFElement> elements = elementSearch.FindElements(0, false, 1000); 
          11. foreach (AFElement element in elements) 
          12.      ProcessElement(element); 




          1 of 1 people found this helpful
            • Re: Create button to do an element Search

              Hi Alan,

              Not sure where you would like to do this search.  PI Builder will not update dynamically based on any new elements that you add into the system.  It is not designed to work that way.  If you're able to use PI System Explorer, you can use the Element Search with Attribute Value Search based on element templates.  As an example, here is a screen shot of what I mocked up in PI System Explorer:



              In this example, I'm doing an element search, based on the element template = Pump, with a Attribute Value search of "Flow Rate >= 100".  Upon hitting OK, you would get a list of search results in PI System Explorer.  As a side note, you can see the search syntax up near the top of the dialog box.


              Hope this helps you.  If not, please better described how you would want to see the search results and then we can provide additional suggestions.


              Steve Kwan

              2 of 2 people found this helpful
            • Re: Create button to do an element Search

              Hi, Alan.

              If you need to have this in Excel, then you could try using the Asset Filter built into DataLink or a PowerPivot table on top of PI Builder results.  The two approaches are outlined for a similar use case in a post I replied to last month:

              Create a data link report

              For the first approach, you could use the Update button in DataLink or build a form control button in Excel that does the same thing (link the button to a macro that does a full calculation on the sheet (Ctrl+Shift+Alt+F9)).

              For the second approach, you would still use the PI Builder Refresh button to update the source data for the pivot table.

              Please post back with your thoughts/questions and what approach you decide upon.