5 Replies Latest reply on Dec 11, 2017 4:33 PM by Roger Palmen

    Custom symbols: how to add items to display errors

    Roger Palmen

      I have built a few custom symbols that use the WebAPI to retrieve more information. However, that information can be incomplete or missing due to functional or technical reasons. Typically i see those in the PI WebAPI returns (e.g. a 404 access denied), or i derive that in code (missing an attribute i need). Anyhow, i now have some error that prevents me from building the visualisation in my symbol.

       

      I could send these errors to the console log, but that leaves the user in the dark. I could add some message to the symbol indicating there was an issue. But i would prefer to do that in the same way as other symbols: add an error message to the display errors (the exclamation mark in the top right corner).

       

      Or making a long question short: how can i add a message to the display error list?

        • Re: Custom symbols: how to add items to display errors
          pmartin

          Hi Roger,

           

          You can inject 'log' into the symbol.

           

          You can add messages through the log.add function:

          add:ƒ (message, severity, details, clearType)

           

          Example:

          symbolVis.prototype.init = function (scope, elem, log){
              log.add("Loaded", log.Severity.Information, "symbol loaded", log.ClearType.NewDisplay);
          }
          
          2 of 2 people found this helpful
            • Re: Custom symbols: how to add items to display errors
              Roger Palmen

              It took me some time to find the time to experiment. Somehow the log object is undefined in my case. Added to a fresh display after restart of browser.

               

              And a side question, what logging framework is behind that? Or in other words, assuming an extension like Microsoft.Extensions.Logging is used, where can i find some syntax of the .add functions and the enumerations?

                • Re: Custom symbols: how to add items to display errors
                  pmartin

                  The logging service is located at PIVision\Scripts\app\common\PIVisualization.log-service.js.  Under the hood it just uses AngularJS's $log service.

                   

                  I'm not sure why you are running into an issue adding log.  I wrote a small test with logging that works on my PI Vision install.  Does it work on yours?

                   

                  window.PIVisualization = window.PIVisualization || {};
                  (function (PV) {
                       'use strict';
                  
                       function symbolVis() { }
                       PV.deriveVisualizationFromBase(symbolVis);
                  
                       symbolVis.prototype.init = function (scope, elem, log){
                            console.log(log);
                            log.add("Loaded", log.Severity.Information, "logger loaded", log.ClearType.NewDisplay);
                       }
                  
                       var def = {
                            typeName: 'logging',
                            datasourceBehavior: PV.Extensibility.Enums.DatasourceBehaviors.Single,
                            visObjectType: symbolVis,
                            inject: ['log'],
                            getDefaultConfig: function(){
                                 return{
                                      DataShape: 'Value',
                                      Height: 1,
                                      Width: 1,
                                 };
                            }
                       };
                  
                       PV.symbolCatalog.register(def);
                  })(window.PIVisualization);
                  
                  2 of 2 people found this helpful