Creating an Azure Function for Custom Query
- Last UpdatedMar 14, 2022
- 3 minute read
Apart from the above-mentioned Azure Function for custom queries, you can define new Azure Function for custom queries.
You can use the the following AVEVA Insight data adapter parameters available in the Azure functions to build new Azure function for custom query.
|
Parameter |
Description |
|
req.body.MhUrl |
AVEVA Insight source URL. |
|
req.body.MhKey |
Token to connect the AVEVA Insight source. |
|
req.body.MhSelectString |
Array of column name. |
|
req.body.MhDateTokenFilterString |
A valid UTC Date time filter string. |
|
req.body.MhAdditonalFilterString |
An additional filter string which could be provided in the custom query expression from the BI Gateway Custom query expression. |
|
req.body.MhTask |
Represents task name as "getSchema"or "getdata"or "getnextpagedata" |
|
req.body.MhQueryName |
A valid azure function query name |
|
req.body.MhRetrievalMode |
Retrieval mode to be used with the Azure function custom query |
|
req.body.MhTop |
Numeric value to fetch top 10 records. |
To add new Azure function
Note: You must have a valid Azure subscription to access and create Azure functions.
-
Log in to the https://portal.azure.com/ using your valid credentials.
-
Add a new javascript file using the function app wizard.
:
-
In the added javascript file, import common libraries and common components.
var request = require('request'); // Library to make asynchronous request
var helper = require('./helper'); // Common component
-
Make sure that the function that you create defines a logic to retrieve entity name and could be used to retrieve the schema of the entity type. For example:
/*
<Summary>
Retrieves Entity name
</summary>
*/
module.exports.GetManagedHistorianEntityName = function () {
return 'Tag';
}
The code sample in the above example use ‘Tag’ entity type.
-
Update the javascript file with the relevant code to retrieve data from the AVEVA Insight source. For example:
module.exports.getSampleTags = function (context, req) {
var urlstring = req.body.MhUrl + '/Tags?$select=' + req.body.MhSelectString;
if (req.body.MhTop != null && req.body.MhTop != undefined
&& req.body.MhTop != "") {
urlstring += "&$top=" + req.body.MhTop;
}
var options = {
url: urlstring,
headers: {
"Authorization": req.body.MhKey
},
method: "GET"
};
request(options, (err, result) => {
if (err) {
context.log(err);
}
context.res = result.body;
context.done();
});
}
The above sample code shows how to retrieve tags data from the AVEVA Insight source.
-
Save and close the javascript file once you have defined your Azure function custom query.
-
Add a reference to the javascript file in the Index.js file available in the Intelligence folder and make the following changes as shown in the screenshot:

-
The added Azure function is now available in the Custom Query editor of the BI Gateway Web Model Configuration application.
NOTE: Make sure you publish the Azure function to your own environment before you can use. You must also update the OnlineInsight.DataAdapter.config file on the BI Gateway computer to point to their Azure function URL when you create your own Azure function.