web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Query CosmosDB, extract matching items, if items do not match, send email

(0) ShareShare
ReportReport
Posted on by 75

I am setting up this LogicApp and want to see if my approach is correct:

 

 

I wish to push data from CosmosDB into CRM, and then return these items back to CosmosDB and replace its ID. Not all of the push to CRM is direct due to some of CRMs fields consisting of 'lookup fields'. I have a list of the GUIDs for the lookup fields, but not every record has a match. For the records that do not have a match, I wish to send an email. This is my flow so far:

 

pastedimage1596679428346v1.png

pastedimage1596679480402v2.png

pastedimage1596679505042v3.png

pastedimage1596679555697v4.png

 

 

 

I am unsure of my highlighted fields here. Is this the correct approach?

Any suggestion or advice is appreciated

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Some of the expressions are not visible correctly like Array****.

    Can you please post the entire code here which will be json format. This you can find from azure portal

    "Logic app code view" below logic app designer.

    Best approach to implement this to use List Records, when List records return [] which means no match found in CRM.

    You can initialize Array variable and for each cosmos DB feature category value not match in CRM you append that data to array variable.

    Now use this array variable to send an email.

    If found helpful, Please mark my answer verified.

  • jasmine202020 Profile Picture
    75 on at

    Sure,  @Bipin,

    I am new to LogicApps, and tried performing the ListRecords action, but I am having a bit of difficulty. I have located the GUIDS within Cosmos, but not all are present. My approach is, since I do have the GUIDS within CosmosDB, I can do a query within cosmosdb to see if: 

    ems_featurecategory value matches what was provided in the CRM, and if there is no match then -> send email notification etc

    Here is my code here: any suggestion is helpful

    (I do not think I will do the ListRecords in this instance)

    {

       "definition": {

           "$schema": "schema.management.azure.com/.../workflowdefinition.json

           "actions": {

               "Add_data_from_THFeatures_container_to_EmptyContainer": {

                   "actions": {

                       "Compose": {

                           "inputs": "@body('Push_Items_into_CRM_(free_form_field)')?['ems_featureid']",

                           "runAfter": {

                               "Push_Items_into_CRM_(free_form_field)": [

                                   "Succeeded"

                               ]

                           },

                           "type": "Compose"

                       },

                       "Condition": {

                           "actions": {

                               "For_each": {

                                   "actions": {

                                       "Matching_value_returned_from_Cosmosdb": {

                                           "inputs": {

                                               "body": {

                                                   "_ems_featurecategory_value": "@{items('For_each')}",

                                                   "_ems_productname_value": "@{body('Parse_JSON')?['ProductInCRM']}",

                                                   "_ownerid_type": ""

                                               },

                                               "host": {

                                                   "connection": {

                                                       "name": "@parameters('$connections')['commondataservice']['connectionId']"

                                                   }

                                               },

                                               "method": "post",

                                               "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('emscrmdev11.crm'))}/tables/@{encodeURIComponent(encodeURIComponent('ems_productfeatures'))}/items"

                                           },

                                           "runAfter": {},

                                           "type": "ApiConnection"

                                       }

                                   },

                                   "foreach": "@body('Query_CosmosDB_for_feature_category_lookup_items')?['Documents']",

                                   "runAfter": {},

                                   "type": "Foreach"

                               }

                           },

                           "else": {

                               "actions": {

                                   "Send_email_with_options": {

                                       "inputs": {

                                           "body": {

                                               "Message": {

                                                   "Importance": "High",

                                                   "Subject": "Feature Category input needed (test message)",

                                                   "To": "test@email.com "

                                               },

                                               "NotificationUrl": "@{listCallbackUrl()}"

                                           },

                                           "host": {

                                               "connection": {

                                                   "name": "@parameters('$connections')['office365']['connectionId']"

                                               }

                                           },

                                           "path": "/mailwithoptions/$subscriptions"

                                       },

                                       "runAfter": {},

                                       "type": "ApiConnectionWebhook"

                                   }

                               }

                           },

                           "expression": {

                               "and": [

                                   {

                                       "equals": [

                                           "@body('Query_CosmosDB_for_feature_category_lookup_items')",

                                           "@body('Query_CosmosDB_for_feature_category_lookup_items')?['Documents']"

                                       ]

                                   }

                               ]

                           },

                           "runAfter": {

                               "Query_CosmosDB_for_feature_category_lookup_items": [

                                   "Succeeded"

                               ]

                           },

                           "type": "If"

                       },

                       "Parse_JSON": {

                           "inputs": {

                               "content": "@items('Add_data_from_THFeatures_container_to_EmptyContainer')",

                               "schema": {

                                   "properties": {

                                       "Blocking": {

                                           "type": "string"

                                       },

                                       "CRMLink": {},

                                       "CXPContact": {

                                           "type": "string"

                                       },

                                       "CreatedBy": {},

                                       "DomainOwnerPriority": {},

                                       "FeatureCategory": {

                                           "type": "string"

                                       },

                                       "FeatureCreatedOnDate": {},

                                       "FeatureId": {

                                           "type": "string"

                                       },

                                       "FeaturePM": {

                                           "type": "string"

                                       },

                                       "FeatureTitle": {

                                           "type": "string"

                                       },

                                       "FeedbackDescription": {

                                           "type": "string"

                                       },

                                       "FeedbackName": {

                                           "type": "string"

                                       },

                                       "FeedbackSource": {

                                           "type": "string"

                                       },

                                       "FeedbackSourceLink": {

                                           "type": "string"

                                       },

                                       "FeedbackSubmittedBy": {

                                           "type": "string"

                                       },

                                       "FeedbackType": {

                                           "type": "string"

                                       },

                                       "Feedbacks": {

                                           "type": "array"

                                       },

                                       "GPM": {},

                                       "Keywords": {

                                           "type": "string"

                                       },

                                       "LeadFeaturePM": {

                                           "type": "string"

                                       },

                                       "ModifiedOnDate": {},

                                       "OrganizationId": {},

                                       "OrganizationName": {},

                                       "OrganizationType": {},

                                       "OwnerInCRM": {

                                           "type": "string"

                                       },

                                       "PGADOLink": {

                                           "type": "string"

                                       },

                                       "PM": {},

                                       "Priority": {

                                           "type": "string"

                                       },

                                       "ProductInCRM": {},

                                       "ReleaseTiming": {

                                           "type": "string"

                                       },

                                       "ReviewStatus": {

                                           "type": "string"

                                       },

                                       "Status": {

                                           "type": "string"

                                       },

                                       "Link": {},

                                       "Title": {},

                                       "VoteRefreshDate": {},

                                       "VotesOnUserVoice": {},

                                       "id": {

                                           "type": "string"

                                       }

                                   },

                                   "type": "object"

                               }

                           },

                           "runAfter": {},

                           "type": "ParseJson"

                       },

                       "Push_Items_into_CRM_(free_form_field)": {

                           "inputs": {

                               "body": {

                                   "_ems_productname_value": "@{body('Parse_JSON')?['ProductInCRM']}",

                                   "ems_featurdescription": "@body('Parse_JSON')?['FeedbackDescription']",

                                   "ems_featurename": "@body('Parse_JSON')?['FeatureTitle']",

                                   "ems_keywords": "@body('Parse_JSON')?['Keywords']"

                               },

                               "host": {

                                   "connection": {

                                       "name": "@parameters('$connections')['commondataservice']['connectionId']"

                                   }

                               },

                               "method": "post",

                               "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('emscrmdev11.crm'))}/tables/@{encodeURIComponent(encodeURIComponent('ems_productfeatures'))}/items"

                           },

                           "runAfter": {

                               "Parse_JSON": [

                                   "Succeeded"

                               ]

                           },

                           "type": "ApiConnection"

                       },

                       "Query_CosmosDB_for_feature_category_lookup_items": {

                           "inputs": {

                               "body": {

                                   "QueryText": "SELECT c.ems_featurecategoryid\nFROM  c\nWHERE c.ems_name = f.FeatureCategory"

                               },

                               "host": {

                                   "connection": {

                                       "name": "@parameters('$connections')['documentdb']['connectionId']"

                                   }

                               },

                               "method": "post",

                               "path": "/v2/dbs/@{encodeURIComponent('uvoc')}/colls/@{encodeURIComponent('THFeature')}/query"

                           },

                           "runAfter": {

                               "Send_items_back_to_CosmosDB,_replacing_its_ID_with_CRM_ID": [

                                   "Succeeded"

                               ]

                           },

                           "type": "ApiConnection"

                       },

                       "Send_items_back_to_CosmosDB,_replacing_its_ID_with_CRM_ID": {

                           "inputs": {

                               "body": {

                                   "CRMLink": "test",

                                   "CreatedBy": "@{body('Push_Items_into_CRM_(free_form_field)')?['_createdby_value']}",

                                   "DomainOwnerPriority": "test",

                                   "FeatureCategory": "@{body('Push_Items_into_CRM_(free_form_field)')?['_ems_featurecategory_value']}",

                                   "FeatureCreatedOnDate": "@{body('Push_Items_into_CRM_(free_form_field)')?['createdon']}",

                                   "FeatureDescription": "@{body('Push_Items_into_CRM_(free_form_field)')?['ems_featurdescription']}",

                                   "GPM": "@{body('Push_Items_into_CRM_(free_form_field)')?['_ems_leadpmforfeature_value']}",

                                   "ModifiedOnDate": "@body('Push_Items_into_CRM_(free_form_field)')?['modifiedon']",

                                   "OwnerInCRM": "@{body('Parse_JSON')?['OwnerInCRM']}",

                                   "ProductInCRM": "@{body('Push_Items_into_CRM_(free_form_field)')['_ems_productname_value']}",

                                   "ReleaseTiming": "@{body('Push_Items_into_CRM_(free_form_field)')?['_ems_releasetimeline_value']}",

                                   "Status": "@{body('Push_Items_into_CRM_(free_form_field)')?['ems_featurestatus']}",

                                   "id": "@{body('Push_Items_into_CRM_(free_form_field)')?['ems_featureid']}"

                               },

                               "headers": {

                                   "x-ms-documentdb-raw-partitionkey": "\"@{body('Parse_JSON')?['OwnerInCRM']}\""

                               },

                               "host": {

                                   "connection": {

                                       "name": "@parameters('$connections')['documentdb']['connectionId']"

                                   }

                               },

                               "method": "post",

                               "path": "/dbs/@{encodeURIComponent('test')}/colls/@{encodeURIComponent('THEmptyContainer2')}/docs"

                           },

                           "runAfter": {

                               "Compose": [

                                   "Succeeded"

                               ]

                           },

                           "type": "ApiConnection"

                       }

                   },

                   "foreach": "@body('Query_THFeature_container_for_specific_results')?['value']",

                   "runAfter": {

                       "Query_THFeature_container_for_specific_results": [

                           "Succeeded"

                       ]

                   },

                   "type": "Foreach"

               },

               "Query_THFeature_container_for_specific_results": {

                   "inputs": {

                       "host": {

                           "connection": {

                               "name": "@parameters('$connections')['documentdb']['connectionId']"

                           }

                       },

                       "method": "get",

                       "path": "/v3/dbs/@{encodeURIComponent('test')}/colls/@{encodeURIComponent('THFeature')}/query",

                       "queries": {

                           "maxItemCount": 1,

                           "queryText": "SELECT * FROM c WHERE length(c.id)>15"

                       }

                   },

                   "runAfter": {},

                   "type": "ApiConnection"

               }

           },

           "contentVersion": "1.0.0.0",

           "outputs": {},

           "parameters": {

               "$connections": {

                   "defaultValue": {},

                   "type": "Object"

               }

           },

           "triggers": {

               "manual": {

                   "inputs": {

                       "schema": {}

                   },

                   "kind": "Http",

                   "type": "Request"

               }

           }

       },

       "parameters": {

           "$connections": {

               "value": {

                   "commondataservice": {

                       "connectionId": "/subscriptions/11/resourceGroups/test/providers/Microsoft.Web/connections/commondataservice",

                       "connectionName": "commondataservice",

                       "id": "/subscriptions/11/providers/Microsoft.Web/locations/westus2/managedApis/commondataservice"

                   },

                   "documentdb": {

                       "connectionId": "/subscriptions/11/resourceGroups/test/providers/Microsoft.Web/connections/documentdb",

                       "connectionName": "documentdb",

                       "id": "/subscriptions/11/providers/Microsoft.Web/locations/westus2/managedApis/documentdb"

                   },

                   "office365": {

                       "connectionId": "/subscriptions/11/resourceGroups/test/providers/Microsoft.Web/connections/office365",

                       "connectionName": "office365",

                       "id": "/subscriptions/11/providers/Microsoft.Web/locations/westus2/managedApis/office365"

                   }

               }

           }

       }

    }

  • jasmine202020 Profile Picture
    75 on at

    @Bipin, do you have any suggestion/advice? Thank you

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans