The Azure DocumentDB Blog

All about DocumentDB and Logic Apps

Using Azure Functions with Logic Apps – Part 2

In part 1,  I mentioned that there is a way to remove NULL values in a Function App.

Using RegularExpressions solves the problem.

#r "Newtonsoft.Json"

using System;
using System.Net;
using Newtonsoft.Json;
using System.Text.RegularExpressions;

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info($"Webhook was triggered!");

    string jsonContent = await req.Content.ReadAsStringAsync();
    var data = System.Convert.ToString(JsonConvert.DeserializeObject(jsonContent));

    log.Info($"source {data}");
    /// <summary>
    /// <para>A Regular Expression to Match any null Json object in a string</para>
    /// <para>like "name":null,</para>
    /// <para>Useful in removing nulls from serialized Json string</para>
    /// </summary>
    var JsonNullRegEx = "[\"][a-zA-Z0-9_]*[\"]:null[ ]*[,]?";

    /// <summary>
    /// <para>A Regular Expression to Match an array of null Json object in a string</para>
    /// <para>like [null, null]</para>
    /// <para>Useful in removing null array from serialized Json string</para>
    /// </summary>
    var JsonNullArrayRegEx = "\\[( *null *,? *)*]";

    if(data == null){
        return req.CreateResponse(HttpStatusCode.BadRequest, new
            {error = "Please pass valid JSON" });
   }
    Regex regex = new Regex(JsonNullRegEx);
    string data1 = regex.Replace(data, string.Empty);
    regex = new Regex(JsonNullArrayRegEx);

    return req.CreateResponse(HttpStatusCode.OK, regex.Replace(data1, "[]"));
}

 

The question: Do Logic Apps support error handling?

Use Case

A well-known Healthcare organization engaged us to create an patient portal on Azure. They were planning on migrating from Salesforce to  CRMOL.

They were currently using Salesforce and we needed to synchronize Patient records between the CRMOL Patient Portal and Salesforce. We were asked to use the HL7 FHIR standard for all Patient records.

Two major requirements that we needed to include were:

  • Logging of records sent from CRMOL Portal
  • They needed a way to view any errors that occur within the workflow.

Find out more on my Integration User Group Webcast this coming Monday.

« Older posts
%d bloggers like this:
Skip to toolbar