Quantcast
Channel: Azure Management Portal forum
Viewing all articles
Browse latest Browse all 4189

Azure logic app - CRM list records and lookup for listed records - update list records JSON with lookup value

$
0
0

Hello!

I'm hoping someone can help.

Currently I have an Azure logic app that monitors sales quotes in CRM. When a quote is approved, the quote and quote product details need to be captured and transformed into a pre-defined XML format for a legacy system.

As part of this process, the product catalog items that will be included have a parent/child relationship. This relationship is used to determine the line numbers for the resulting XML.

I can easily use the header record from the dynamics 365 updated record action and use the dynamics 365 list records action to pull the quote product details (which would be JSON with an array of items for the quote). If I didn't have to do the product catalog lookup for the parent, I could construct a schema that could be used in the transform XML action to create the legacy system format.

Where I am experiencing the trouble is with the lookup part. I have to iterate through the list records action results. In this loop, I have another logic app I connect to to do the product catalog lookup for the parent field. But, this yields me singular body results for each array item as I loop through the list records results. I can work with that individual item, but I don't know how to get the results back into a JSON that includes all the records from the loop. It's the full set of quote products that I need so that I can use the transform XML action to create the resulting XML.

If I was doing this in straight up code, I'd have a variable outside the scope of a for loop and append the changes through each iteration, thus yielding a full set of results from the for loop processing. This is (to my knowledge) not something that we can do in Azure logic apps.

If anyone has any suggestions, I'd appreciate it immensely!

Thanks so much in advance!


Here is some scrubbed WDL for reference. There are a couple functions that are referenced as well to transform data and attempt to insert the parent ID into the list records action items.


{
    "$connections": {
        "value": {
            "dynamicscrmonline": {
                "connectionId": "/subscriptions/abc123",
                "connectionName": "abc123",
                "id": "/subscriptions/abc123"
            },
            "office365": {
                "connectionId": "/subscriptions/abc123",
                "connectionName": "office365",
                "id": "/subscriptions/abc123"
            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Condition": {
                "actions": {
                    "For_each": {
                        "actions": {
                            "Condition_2": {
                                "actions": {
                                    "UpdateQuoteProductWithParentProductNumber": {
                                        "inputs": {
                                           "body": "@json(replace(string(item()),'\"_abc_productfamily_value\":null',concat('\"_abc_productfamily_value\":\"',body('QuoteProductLookup')['value'][0]['_new_parentproduct_value'],'\"')))",
                                           "function": {
                                               "id": "/subscriptions/abc123"
                                            }
                                        },
                                        "runAfter": {},
                                        "type": "Function"
                                    }
                                },
                                "expression": "@greater(length(body('QuoteProductLookup')['value']), 0)",
                                "runAfter": {
                                    "QuoteProductLookup": [
                                        "Succeeded"
                                    ]
                                },
                                "type": "If"
                            },
                            "QuoteProductLookup": {
                                "inputs": {
                                    "body": {
                                        "productnumber":"@{item()?['abc_partnumber']}"
                                    },
                                    "host": {
                                        "triggerName":"manual",
                                        "workflow": {
                                           "id": "/subscriptions/abc123"
                                        }
                                    }
                                },
                                "runAfter": {},
                                "type": "Workflow"
                            }
                        },
                        "foreach": "@body('List_records')?['value']",
                        "runAfter": {
                            "List_records": [
                                "Succeeded"
                            ]
                        },
                        "type": "Foreach"
                    },
                    "List_records": {
                        "inputs": {
                            "host": {
                                "api": {
                                    "runtimeUrl": "https://logic-apis-centralus.azure-apim.net/apim/dynamicscrmonline"
                                },
                                "connection": {
                                    "name": "@parameters('$connections')['dynamicscrmonline']['connectionId']"
                                }
                            },
                            "method": "get",
                            "path": "/datasets/@{encodeURIComponent(encodeURIComponent('abctech-dev1.crm'))}/tables/@{encodeURIComponent(encodeURIComponent('quotedetails'))}/items",
                            "queries": {
                                "$filter": "quoteid/quoteid eq @{triggerBody()?['quoteid']}"
                            }
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    },
                    "Send_an_email": {
                        "inputs": {
                            "body": {
                                "Body": "@{replace(string(body('Transform_XML')),'Reference1>', 'Reference>')}",
                                "Subject": "xml from new record",
                                "To": "test@abc.com"
                            },
                            "host": {
                                "api": {
                                    "runtimeUrl": "https://logic-apis-centralus.azure-apim.net/apim/office365"
                                },
                                "connection": {
                                    "name": "@parameters('$connections')['office365']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/Mail"
                        },
                        "runAfter": {
                            "Transform_XML": [
                                "Succeeded"
                            ]
                        },
                        "type": "ApiConnection"
                    },
                    "Send_an_email_2": {
                        "inputs": {
                            "body": {
                                "Body": "@{string(body('UpdateLineItemNumber'))}",
                                "Subject": "XML for new schema",
                                "To": "test@abc.com"
                            },
                            "host": {
                                "api": {
                                    "runtimeUrl": "https://logic-apis-centralus.azure-apim.net/apim/office365"
                                },
                                "connection": {
                                    "name": "@parameters('$connections')['office365']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/Mail"
                        },
                        "runAfter": {
                            "UpdateLineItemNumber": [
                                "Succeeded"
                            ]
                        },
                        "type": "ApiConnection"
                    },
                    "Send_an_email_3": {
                        "inputs": {
                            "body": {
                                "Body": "@string(body('List_records')?['value'])",
                                "Subject": "is the part number updated?",
                                "To": "test@abc.com"
                            },
                            "host": {
                                "api": {
                                    "runtimeUrl": "https://logic-apis-centralus.azure-apim.net/apim/office365"
                                },
                                "connection": {
                                    "name": "@parameters('$connections')['office365']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/Mail"
                        },
                        "runAfter": {
                            "For_each": [
                                "Succeeded"
                            ]
                        },
                        "type": "ApiConnection"
                    },
                    "Transform_XML": {
                        "inputs": {
                            "content": "@{xml(concat('<fullQuote>',xml(json(replace(string(body('UpdateLineItemNumber')), '\"data\":', '\"quoteProducts\":'))),xml(json(replace(string(body('XmlToJsonConversion_Header')), '\"data\":', '\"quote\":'))),'</fullQuote>'))}",
                            "integrationAccount": {
                                "map": {
                                    "name": "Outbound_Quotes_CRM_To_Omar"
                                }
                            }
                        },
                        "runAfter": {
                            "XmlToJsonConversion_Header": [
                                "Succeeded"
                            ]
                        },
                        "type": "Xslt"
                    },
                    "UpdateLineItemNumber": {
                        "inputs": {
                            "body": "@body('List_records')",
                            "function": {
                                "id": "/subscriptions/abc123"
                            }
                        },
                        "runAfter": {
                            "XmlToJsonConversion_Lines": [
                                "Succeeded"
                            ]
                        },
                        "type": "Function"
                    },
                    "XmlToJsonConversion_Header": {
                        "inputs": {
                            "body": "@triggerBody()",
                            "function": {
                                "id": "/subscriptions/abc123"
                            }
                        },
                        "runAfter": {
                            "Send_an_email_2": [
                                "Succeeded"
                            ]
                        },
                        "type": "Function"
                    },
                    "XmlToJsonConversion_Lines": {
                        "inputs": {
                            "body": "@body('List_records')",
                            "function": {
                                "id": "/subscriptions/abc123"
                            },
                            "headers": "@triggerBody()"
                        },
                        "runAfter": {
                            "Send_an_email_3": [
                                "Succeeded"
                            ]
                        },
                        "type": "Function"
                    }
                },
                "expression": "@equals(1, 1)",
                "runAfter": {},
                "type": "If"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_record_is_updated": {
                "inputs": {
                    "host": {
                        "api": {
                            "runtimeUrl": "https://logic-apis-centralus.azure-apim.net/apim/dynamicscrmonline"
                        },
                        "connection": {
                            "name": "@parameters('$connections')['dynamicscrmonline']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('abctech-dev1.crm'))}/tables/@{encodeURIComponent(encodeURIComponent('quotes'))}/onupdateditems"
                },
                "recurrence": {
                    "frequency": "Second",
                    "interval": 15
                },
                "splitOn": "@triggerBody()?.value",
                "type": "ApiConnection"
            }
        }
    }
}


Viewing all articles
Browse latest Browse all 4189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>