Logic App to push data from Cosmosdb into CRM and performing updates

Jasmine2020 1 Reputation point
2020-07-24T23:04:55.937+00:00

I have created a logic app with the goal of pulling data from a container within cosmosdb (with a query), looping over the results and then pushing this data to CRM. When the data is pushed to CRM, an ID will be created and I wish to then update cosmosdb with this new ID. Here is what I have so far:

13648-image.png

This next step is querying for the data within our cosmosdb database and selecting all IDS with a length that is greater than 15. (This tells us that the ID is not yet within the CRM database)

13667-image.png

Then we loop over the results and push this into CRM (Dynamics365 or the Common Data Service)

13649-image.png

Dilemma: The first part of this process appears to be correct, however, I want to make sure that I am on the right track with this. Furthermore, once the data is successfully pushed to CRM, CRM automatically generates an ID for each record. How would I then update cosmosDB with the newly generated IDs?

13650-image.png

Any suggestion is appreciated

Thanks

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,868 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,454 questions
{count} votes

1 answer

Sort by: Most helpful
  1. QuantumCache 20,031 Reputation points
    2020-07-27T19:22:22.137+00:00

    Referencing the Answer provided by Microsoft Team on Stackoverflow:

    I see a red flag in your approach here with this query with length(c.id) > 15. This is not something I would do. I don't know how big your database is going to be but generally not very performant to do high volumes of cross partition queries, especially if the database is going to keep growing.

    Cosmos DB already provides an awesome streaming capability so rather than doing this in a batch I would use Change Feed and use that to accomplish whatever your doing here in your Logic App. This will likely give you better control of the process and likely allow you to get the id back out of your CRM app to insert back into Cosmos DB.

    Because you will be writing back to Cosmos DB, you will need a flag to ignore the update in Change Feed when the item is updated.

    Please refer to Change feed in Azure Cosmos DB

    1 person found this answer helpful.