Quite often before D365 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 & 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.
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 Function App –
Then create a new function using a template, or from blank –
HttpTrigger C# Template –
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.
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 a Azure Function action, and select the Function you created,
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.
Azure Function App Documentation