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

Is it possible to use a variable for Segment ID in "IncludeMemberinSegment" workflow?

(0) ShareShare
ReportReport
Posted on by

I am launching a workflow from a Customer Journey that will add the Contact to a Segment.  I am using "IncludeMemberinSegment".  This works great, but I have to hard-code the Segment ID.

Rather than hard-coding the Segment ID, I want to dynamically generate the value based on the Customer Journey.  For example - Tell me the Segment ID of the Segment whose name is the same as the Customer Journey.

Is this possible?  How can I tell the workflow to get the Segment ID of a Segment whose Name is the same as the Customer Journey?

I have the same question (0)
  • Suggested answer
    Joseph M. Profile Picture
    25 on at

    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!

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    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:

    pastedimage1578640905955v12.png

    3. Overview of flow:

    When a record is selected tile will only appear from step 2

    pastedimage1578638679966v2.png

    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

    pastedimage1578638982708v3.png

    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

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/walkthrough-register-app-azure-active-directory

      5.2 Grant admin access to the app to call D365 API

     (1) Add Dynamics CRM permission,

     (2) Grant admin consent for Contoso 

    pastedimage1578639583407v4.png

    5.3 In manifest file, set those 3 fields to True

    pastedimage1578639779581v5.png

    5.4 We need those 2 parameters:

    client ID and tenant ID

    pastedimage1578639965019v7.png

    6. Tile 4 is called HTTP action(search to find it), rename it to GetAppToken

    pastedimage1578640092822v8.png

    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

    pastedimage1578640380616v9.png

    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.

    pastedimage1578640532341v10.png

    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

    pastedimage1578640850283v11.png

    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

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 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

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

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans