Nowadays, multiple organizations are storing their data everywhere, it is in Cloud or On-premise and it is increasing day by day with the help of internet connectivity. Organizations are asking their developers to respond with highly-scalable solutions. Solutions that often require developers to implement on-demand or scheduled batch jobs to reconcile transactions, ingest and process data, or react to events in real-time. To accomplish this huge demand we have Azure functions.
Azure Functions is a serverless compute service that lets you run event-triggered code without having to explicitly provision or manage infrastructure.
Today we will see how to call an azure function from the below components.
You can use below jquery code in your JavaScript to trigger azure function and you can also pass the expected parameter in that request.
function TriggerAzurefunction()
{
var urlPath = "https:// functioncreatemultiplecontact20200723025939.azurewebsites.net/api/CreateMultipleBookings?code=XktEMAGwdjCXKIksnSKTdFKGP/iqo9WiJMYkTMObAa07bkBcYKrjaQ==&name=testname ";
if (typeof($) === 'undefined') {
$ = parent.$;
jQuery = parent.jQuery;
}
$.ajax({
url: urlPath,
type: "GET",
dataType: "json",
async: false,
crossDomain: true,
success: function (data, textStatus, xhr) {
return JSHelper.toJson(data);
},
error: function () {
}
})
.done(function (data, status, jqxhr) {
});
}
public void CallAzureFunction()
{
//create MemoryStream object to pass parameters
MemoryStream memoryStream = new MemoryStream();
var jsonObject = Encoding.Default.GetString(memoryStream.ToArray());
//creat web client object to call http request.
var webClient = new WebClient();
//Add required headers.
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
//Azure function URL you can query parameters as below
var serviceUrl = "https:// orderscreate.azurewebsites.net/api/Function1?code=RUydvGtO6IHRLhWjagoKUYaa0WQfJcBXq39SYSEuYbQ==&OrderNo=" + OrderNumber + "&Orderid=" + Entity.Id.ToString();
//upload the data using Post method
string response = webClient.UploadString(serviceUrl, jsonObject);
}
1. URI: Provide azure function URL (you will get it in azure portal)
2. Headers: “code” and value, provide your azure function security code in header as shown below.
3. Queries: provide your parameters as per your requirement.
Check out my recent blog post:
Original Post https://vikrantsdynamicsblogs.wordpress.com/2020/07/27/multiple-ways-to-call-azure-function-in-dynamics-365/