I created sample custom symbol that can put value to PI Data Archive by PI Coresight 2016. (I use PI Web API to write value)

(In this display I put "200" value to cdt158 tag.) It is possible to write value to AF attribute too!

Put the new value to the box and click "Put New Value" text. It uploads the new value to PI data Archive or AF with current timestamp by PI Web API.

It can be hided by right click > Format Symbol

The point is that this code uses PI Web API Batch request.

Copy following 3 files to %PIHOME64%\Coresight\Scripts\app\editor\symbols\ext folder.

Also copy the image (attaced pen.svg) to %PIHOME64%\Coresight\Images folder.

sym-putvalue.js (Please change var piwebapiaddress = "MachineName"; to your PI Web API machine name. PI Coresight machine contains PI Web API. So it should be PI Coresight machine name)

(function (CS) {
    var definition = {
        typeName: 'putvalue',
        datasourceBehavior: CS.DatasourceBehaviors.Single,
        iconUrl: 'Images/pen.svg',
        getDefaultConfig: function() {
            return {
                DataShape: 'Value',
                Height: 150,
                Width: 150,
                TextColor: 'rgb(255,255,255)',
                ShowLabel: true,
                ShowTime: true,
                ShowPutValue: true              
            };
        },
        configOptions: function () {
            return [{
                title: 'Format Symbol',
                mode: 'format'
            }];
        },
        init: init
    };
    function init(scope) {
        function onUpdate(data) {
            if(data) {
                scope.value = data.Value;
                scope.time = data.Time;
                if(data.Path){
                    scope.path = data.Path;
                }
                if(data.Label) {
                    scope.label = data.Label;
                }
            }
        }
        scope.putvalue = function() {
            //piwebapiserver machine name
            var piwebapiaddress = "MachineName";
            //scope.path contains pi:\\servername\tagname or af:\\servername\databasename\element...|attribute
            var ini = scope.path.substr(0,3);
            var orgpath = scope.path.substr(3,10000);
            //To double the backslash -  \\\\servername\\tagname
            var path = orgpath.replace(/\\|\\/g,"\\\\");
            if(ini=="pi:"){
                var urladdress = "\"https://" + piwebapiaddress + "/piwebapi/points?path="+path+"\"";
            }
            else if(ini=="af:"){
                var urladdress = "\"https://" + piwebapiaddress + "/piwebapi/attributes?path="+path+"\"";
            }
            //Get text box value
            var boxval = new String(scope.config.Box, { "type" : "text/plain" });
            //Create value contents as json
            var jsonval = '"{Value:' + boxval + '}"';
            // Create contents of PI Web API batch request
            var contents = '{"GetWebID":{"Method": "GET","Resource": '+ urladdress + '},"WriteValuetoPI":{"Method":"POST","Resource": "{0}","Content":' + jsonval + ',"Parameters": ["$.GetWebID.Content.Links.Value"],"ParentIds": ["GetWebID"]}}';

            //PI Web API Request
            var batchurl = "https://" + piwebapiaddress + "/piwebapi/batch";
            var xhr= new XMLHttpRequest();
            //true = Async call
            xhr.open("POST",batchurl,true);
            //Set credential for Kerberos
            xhr.withCredentials = true;
            xhr.setRequestHeader('Content-Type','application/json');
            //Send request
            xhr.send(contents);
        };
        return { dataUpdate: onUpdate };
    }
    CS.symbolCatalog.register(definition);
})(window.Coresight);

 

sym-putvalue-config.html

<div class="c-side-pane t-toolbar">
    <span style="color:#fff; margin-left:15px">Text Color</span>
</div>
<format-color-picker id="textColor" property="TextColor" config="config"></format-color-picker>
<div class="c-side-pane t-toolbar">
    <span style="color:#fff; margin-left:15px">Background Color</span>
</div>
<format-color-picker id="backgroundColor" property="BackgroundColor" config="config"></format-color-picker>
<div class="c-side-pane t-toolbar">
    <span style="color:#fff; margin-left:15px">Show Options</span>
</div>
<div class="c-config-content">Show Label:
    <input type="checkbox" ng-model="config.ShowLabel">
</div>
<div class="c-config-content">Show Time:
    <input type="checkbox" ng-model="config.ShowTime">
</div>
<div class="c-config-content">Show PutValue:
    <input type="checkbox" ng-model="config.ShowPutValue">
</div>

 

sym-putvalue-template.html

<div ng-style="{background: config.BackgroundColor, color: config.TextColor}">
    <div ng-show="config.ShowLabel">{{label}}</div>
    <div id='valueCSV'>{{value}}</div>
    <div ng-show="config.ShowTime">{{time}}</div>
    <div id='putvalue' ng-show="config.ShowPutValue">
    Enter new value :<br>
    <input type="text" style="margin-left:5px; width:100px;" name="box" ng-model="config.Box" /><br>
    <a name='putvalue' type="button" ng-click="putvalue()">Put New Value</a><br>
    </div>
</div>

 

You can find these files in GitHub too.

GitHub - kenji0711/PICoresight2016-CustomSymbol-PutValue: PI Coresgiht 2016's custom symbol that can write value to PI b…

 

At least, the next version of PI Coresight will not have write value function.

So it is useful to call PI Web API in the PI Coresgiht custom symbol to write value or get summary values. So this is an example.

For using PI Web API from custom symbols, I needed to change CoresMethods = *, CorsHeaders = *, CorsOrigins = * and CorsSupportsCredentials = True in the AF configuration database. (I use Kerberos as Authentication Methods)

Also certificate should be global signed one or registered by the client machine for avoiding the certificate error.

If you could not write value, then you can troubleshoot by Google Chrome on client machine.

Open the page, click F12 key. You can see developers details information.

Click "Put New Value" and you can see the error message.