Getting Members of a D365 Marketing List (Static *AND* Dynamic) Using Power Automate.
Don't Call it a Comeback, I've been here for years.
Ok, not really. But it's still not really a comeback...yet. I started a new job in March (finally doing Power Platform stuff full time!) and it's taken most of my blogging/video/podcast time. The good news is that I get to work on even more cool projects and learn loads of things along the way. But, it means getting used to a blog format that supports small tidbits of information, rather than big walkthroughs. Today, for example, I found a neat trick for getting the members of a dynamic marketing list in Microsoft Dynamics 365 CE/Sales/CRM.
I found plenty of examples to grab the members of a static list, but nothing around dynamic lists, so I'm wondering if this feature is relatively new, or maybe I'm the only one using Marketing Lists still.
My project entailed going through each active campaign, and sending an adaptive card to the members, so the first struggle was figuring out how marketing lists are associated to the campaigns. Thanks to Matt Beard, I didn't have to struggle for long: That relationship is stored in the Campaign Item table, and we'll look for an "entity type" of Marketing List (value = 4300 in OOB D365). I leveraged FetchXML Builder in XRMToolbox to create the query below:
This step will provide a list of all of the marketing lists associated with that campaign, so the next step is to work through each of those to get a list of contacts. Since the method for a dynamic list is different from a static list, we need to first find which type of list it is.
Inside my Apply to Each loop, I have a Dataverse "Get Row by ID" step, using the Entity ID from my Campaign Items array. This gets the details for each respective marketing list. I'm not sure why, but "Type" is false for static lists, so I use that as my condition. I'm certain there are other, more elegant, ways...but this is my hammer.
For static lists, it's simply a matter of cycling through the listmember table where the listid is equal to the marketing list you're interested in.
I've used the dynamic value from my previous step in the Fetch XML query detailed to the left.
For dynamic lists, it's actually even easier. The marketing list record includes the Fetch XML query used to get the list of members, so we just need to drop that column in the Fetch XML Query field on the Dataverse List Rows action:
Keep in mind that marketing lists can consist of Leads or Contacts, so if you're expecting either/both, then you'll want to build in logic to account for that. In my scenario, we are only using Contacts, so I didn't have to build in a Leads path.
I hope this helps someone out there battling a similar scenario. It took some digging to get to this solution, but so far it seems pretty stable and effective.
Jump in, break things. Try. Fail. Learn. Repeat.