Hi Stephani,
As joseph suggested, due to you need to retrieve a segment record based on Name field value of a customer journey,
and there is no retrieving functionality in OOB workflow, so in traditional way your should build a custom workflow activity with C#,
create a local variable to save retrieved segment ID, then call the action with custom variable to complete whole process,
which requires us to be familiar with developer tool.
So I also recommend do it with Flow,(power automate) it's low code environment.
The only challenge would be that we need to call "IncludeMemberinSegment" action, normally there are only CRUD operations available.
1. Read this article for enable Flow function for CRM:
https://www.crmsoftwareblog.com/2019/11/on-demand-microsoft-flow-for-dynamics-365-and-powerapps/
2. After everything is ok in step 1, create a flow via the Flow Ribbon button:
3. Overview of flow:
When a record is selected tile will only appear from step 2
4. Tile 2 and tile 3 are easy to configure:
retrieve customer journey name from contact's source customer journey field,
then retrieve the segment by retrieved customer journey Name
5. Tile 4 is very important, because there are only CRUD operaions,
so we need to connect back to CRM again to get access token,
then call IncludeMemberinSegment action in Web API format.
5.1 Follow the guide to register an Azure Active Directory app,
you'll get these required paratemers in following steps.
- client ID
- URL to get access token
5.2 Grant admin access to the app to call D365 API
(1) Add Dynamics CRM permission,
(2) Grant admin consent for Contoso
5.3 In manifest file, set those 3 fields to True
5.4 We need those 2 parameters:
client ID and tenant ID
6. Tile 4 is called HTTP action(search to find it), rename it to GetAppToken
Here is a template, please copy paratemeters to corrensponding fields.
Method: POST URI: https://login.microsoftonline.com/tenant-ID/oauth2/token Headers Content-Type: application/x-www-form-urlencoded Body grant_type=password& client_id=client-ID& username=yourCRMMailbox& password=pwd& resource=https://org.crm.dynamics.com/
7. In tile 5, create a variable to save access token, we'll send our request with this string to CRM Web API.
Copy this:
@{body('GetAppToken')['access_token']}to Value field
8. Create a new HTTP request: "Add to segment",
the Outer Apply to each will automatically appear and surround HTTP tile when we populate data.
Method: POST URI: https://orgURL/api/data/v9.0/msdyncrm_IncludeMemberInSegment Authorization: Bearer ${access_token} Accept: application/json Content-Type: application/json; charset=utf-8 OData-MaxVersion: 4.0 OData-Version: 4.0 Body { "msdyncrm_segmentid": ${segmentid} "msdyncrm_segmentmemberid": ${contactid} }
9. Run for test
Due to on-demand flow(also workflow) is restricted to be synchronous, so you could only select one record each time to perform flow,
(even if you run for bulk records, flow will only run on a random one)
then see result in the Segment whose name is same to contact's source customer journey name.
Member contact records will be checked when you stop the segment.
Regards,
Clofly
Hi Stephani,
You could definitely do that via flow!
If for example in your customer journey you are creating a lead, the customer journey field on the lead is automatically filled, the contact information as well.
You can then create a flow that triggers on creation of the lead with a filled customer journey lookup, and that searches for the segment having the same name.
Then you can add the contact to the first found segment or to all the segments.
Hope this answers your question!
André Arnaud de Cal...
293,138
Super User 2025 Season 1
Martin Dráb
231,895
Most Valuable Professional
nmaenpaa
101,156
Moderator