CLOSE
CLOSE
https://www.sikich.com

Using Azure Function Apps to Manipulate Data in Dynamics 365

Quite often before Dynamics 365 can process our inbound message, we need to manipulate it. This might be changing the structure of the data or changing values. As with most things, there is more than one way to skin a cat, but you could make a strong argument that the best way to approach this would be to use the Azure Enterprise Integration Pack along with XML and/or flat file schemas.

In smaller and simpler scenarios, this could be overkill. The Enterprise Integration adds a lot of nice capabilities, but also adds complexity and the extra $1,000 per month can be a hard sell.

A simpler approach could be to utilize an Azure Function App, called from a Logic App. A Function App is essentially a serverless compute service, written in JavaScript, C# or F#, that can run a piece of code on demand, and scale out as needed. Pricing is considerably more attractive than an Enterprise Account, if you do not need all of those features.

In this quick example, we’re receiving data from a trading partner, and need to manipulate it before passing it on to D365 via our REST API.

First, create a new Azure Function App.

using Azure function apps

using Azure function apps

Then create a new function using a template, or from scratch.

using Azure function apps

The following is an example of the HttpTrigger C# Template:

using Azure function apps

This simple example expects to receive a key value parameter, of eg name=Rob, and returns the string “Hello Rob” if passed correctly.

Here’s our modified code. Say we want to remove all lines that do not start with “0.” Our inbound message is one long string. We can convert that to an array, and use the filter method to obtain a subset of lines that start with “0.” Lastly, we convert the array back to a string, and return it to our Logic App.

#r “Newtonsoft.Json”using System.Net;

using Newtonsoft.Json;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{

string jsonContent = await req.Content.ReadAsStringAsync();

dynamic data = JsonConvert.DeserializeObject(jsonContent);

string dataString = data.body;

string[] lines = dataString.Split(‘n’);

lines = Array.FindAll(lines, s => s.StartsWith(“0”));

return req.CreateResponse(HttpStatusCode.OK, String.Join(“n”, lines));

}

The function returns the modified data back to our Logic App, which can then pass it on to D365.

To call the Function App from the Logic App, add an Azure Function action, and select the Function you created.

using Azure function apps

using Azure function apps

The input to the action should be the contents of the file. The output of the action will be the output of the function – the filtered message body.

using Azure function apps

This publication contains general information only and Sikich is not, by means of this publication, rendering accounting, business, financial, investment, legal, tax, or any other professional advice or services. This publication is not a substitute for such professional advice or services, nor should you use it as a basis for any decision, action or omission that may affect you or your business. Before making any decision, taking any action or omitting an action that may affect you or your business, you should consult a qualified professional advisor. In addition, this publication may contain certain content generated by an artificial intelligence (AI) language model. You acknowledge that Sikich shall not be responsible for any loss sustained by you or any person who relies on this publication.

About the Author