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,...
Answered

Have you tried to "IncludeMembersInSegment" using a CRM Workflow?

(0) ShareShare
ReportReport
Posted on by

I am attempting to add a contact to a segment through a CRM Workflow.  I found the action "IncludeMembersinSegment".  It asks for two properties:

1. msdyncrm_segmentid
- I put the ID from the URL (see screenshot)

2. msdyncrm_segmentmemberids
- I put {Contact((Contact))}

Any thoughts on why this step is failing?

pastedimage1575914209562v1.png

I have the same question (0)
  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Stephani,

    The reason is your step 2.

    IncludeMembersinSegment is used to add contacts in a static segment.

    In a static segment, members will be saved and formatted as an array in "msdyncrm_segmentmemberids" field:

    ["crmbdbf9a01-b056-e711-abaa-00155d701c02","crm3c0e75b6-1f05-ea11-a811-000d3a33e312",...rest

    However, from my test, the action won't recognize {Contact((Contact))} as the contact's guid instead the dynamic value will be directly output as contact fullname.

    So if you would like to perform the action in workflow, you should create a custom field to save guid value of contact then do concatenation in the second input line.

    e.g: crm{Contact Guid(Contact)}

    Then you could run workflow successfully.

    * Please notice: 

    from my test, the workflow failed at bulk operation, 

    I thought that because members are array items, there was no extra process to concat bulk records into an array in IncludeMembersinSegment action.

    But I couldn't give a specific answer or explanation for the bulk operation failure due to the action is not a recommended or published way to add contacts to static segment.

    ----------

    While the recommended way to create a segment with contacts is by web api:

    https://docs.microsoft.com/en-us/dynamics365/marketing/developer/extend-segments#crud-operations-on-static-segments

    You could run following code in a web resource to test:

    function addMemberToMaoSegment() {
      var clientUrl = parent.Xrm.Page.context.getClientUrl();
      var query = "msdyncrm_segments";
      try {
        var data = {
          "msdyncrm_segmentname": "Mao test segment",
          "msdyncrm_segmenttype": 192350001,
          "msdyncrm_segmentmemberids": "[\"crm49c09a01-b056-e711-abaa-00155d701c02\",\"crm25242b01-c703-4b1c-a24c-c26da8ae508c\"]",
          "statuscode": 192350000
        };
        var req = new XMLHttpRequest();
        req.open("POST", clientUrl   "/api/data/v9.1/"   query, true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.onreadystatechange = function() {
          if (this.readyState == 4) {
            req.onreadystatechange = null;
            if (this.status == 204) {
              alert('ok');
            } else {
              var error = JSON.parse(this.response).error;
              alert("error when send request: "   error.message);
            }
          }
        };
        req.send(JSON.stringify(data));
      } catch (err) {
        alert("error when execute function: "   err);
      }
    }

    It will create a static segment with two existing contacts.(replace crmxxx as yours)

    Finally, no matter what method you take, 

    another point should be noticed is that added contacts could be only viewed in Members tab in a live static segment,

    we need to add new criteria to filter the newly added out.(But they'll be selected and Members field data will also updates)

    Regards,

    Clofly 

  • Stephani Profile Picture
    on at

    Clofly, I'm always impressed with how thorough your response is.  Yes, this worked - I added an action prior to the IncludeMemberInSegment to get the GUID and then was able to reference it in the IncludeMemberInSegment.  I just don't understand why MS would build it that way when it should be able to use Contact(Contact).  Regardless, this worked.  Thanks!

  • Stephani Profile Picture
    on at

    Oh I should also add, I had to put the Segment ID in {}

  • Raja Emmadisetty Profile Picture
    20 on at

    Hi Stephani 

    I am trying call action from workflow to add contacts to segments. I have stored GUID of contact in a field and referencing it. But still workflow is failing with the below error.

    pastedimage1620373369011v1.png

    Action Parameters:

    msdyn_segmentid  =  {SegmentGuid}

    msdyncrm_segmentmemberids = ["crm+contactGuid"]

    Am I missing something ?

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

#2
#ManoVerse Profile Picture

#ManoVerse 110

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans