Tuesday, April 25, 2017

Logic Apps and EDI (II)

This post continues the Logic Apps and EDI series of post, that I began last week.

In this post I want to explain, how to manage errors when Resolve EDIFACT Agreement doesn't found the agreement or any other error.



At this moment, in the Logic Apps editor, we can't insert a fail condition after the execution of a step. We have to insert by code, then in my previous Logic App I will add a new step, Office 365 Outlook Send an Email to send an email when Resolve EDIFACT Agreement works without errors, with these properties:

 - Body:
"@{concat('Resolved correctly the agreement ', body('Resolve_EDIFACT_agreement')?['AgreementName'])}"

- Subject:
"@{concat(body('Resolve_EDIFACT_agreement')?['AgreementName'], ' found')}"

- To:
"FMondelo@kabel.es"

And after I add another new step, Office 365 Outlook Send an Email to send an email when Resolve EDIFACT Agreement works with errors, with these properties:

 - Body:
"Agreement not found"

Subject:
"Agreement not found"

To:
"FMondelo@kabel.es"

At this moment, this is my Logic App:


Now I have to switch to Code View to capture the error on Resolve EDIFACT Agreement and send the correct email. Find 'Send an email 2' and change the runAfter property:

"runAfter": {
                    "Send_an_email": [
                        "Succeeded"
                    ]
                },

By this:

"runAfter": {
                    "Resolve_EDIFACT_agreement": [
                        "Failed"
                    ]
                },

Now, if I switch to the Designer View, this is my Logic App now:



The last step is put on the error email, the error details. Then I modify the 'Send an Email 2' properties with these values:

- Body:
 "@{body('Resolve_EDIFACT_agreement')?['ErrorMessage']}"

- Subject:
"@{concat('Error trying to find the agreement - ', body('Resolve_EDIFACT_agreement')?['StatusCode'])}"

- To:
"FMondelo@kabel.es"

Now, if we receive an EDI file where the agreement is not set, we will receive an email like this:



To be continued....

No comments: