2 Replies Latest reply on Nov 20, 2017 1:15 AM by yihan

    PI Vision: how to access to Attribute's limits value through javascript

    yihan

      Hi,

       

      I would like to know how do I obtain the attribute's limits value in javascript?

      I have tried data.TargetData.data, data.Limits, all these does not work. I am using it for the radial gauge.

      12121.PNG

      I need the green/ yellow and red color portion change dynamically according to the limits I set for each attributes, right now I need to manually key in the values.

      Thanks for the help.

        • Re: PI Vision: how to access to Attribute's limits value through javascript
          pmartin

          Hi Yihan,

           

          I think there's a way in PI Vision to get these traits but I haven't quite figured it out yet.  In the meantime, you can use the PI Web API in order to get this data.  I've written a batch request that will get the the traits for a particular attribute:

           

          {
              "1": {
                  "Method": "GET",
                  "Resource": "https://<web api server>/piwebapi/attributes?path=<Get path from data.Path>",
              },
              "2": {
                    "Method": "GET",
                    "Resource": "$.1.Content.Links.Attributes",
                    "ParentIds": [
                          "1"
                    ],
              },
              "3": {
                    "Method": "GET",
                    "RequestTemplate": {
                        "Resource": "$.2.Content.Items[?(@.TraitName!='')].Links.Value"
                    },
                    "ParentIds": [
                        "2"
                    ]   
              }
          }
          

           

          You can call the Web API using the $httpProvider or jQuery ajax (whichever you feel more comfortable with).

           

          The ajax request would look like:

          $.ajax({
               url: "https://<server>/piwebapi/batch,
               type: "POST",
               contentType: "application/json",
               data: <the above batch request>,
               xhrFields: {
                 withCredentials: true
               }
          })
          .done(function(data, textStatus, xhr){
               //parse results
          })
          .fail(function(xhr, textStatus, errorThrown){
               console.log(xhr.status + '\n'  + textStatus + '\n' + errorThrown + '\n' + xhr.responseText + '\n');
          });
          
          1 of 1 people found this helpful