Skip to main content

Notifications

Announcements

No record found.

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

  • Raja Emmadisetty Profile Picture
    Raja Emmadisetty 20 on at
    RE: Have you tried to "IncludeMembersInSegment" using a CRM Workflow?

    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 ?

  • Stephani Profile Picture
    Stephani on at
    RE: Have you tried to "IncludeMembersInSegment" using a CRM Workflow?

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

  • Stephani Profile Picture
    Stephani on at
    RE: Have you tried to "IncludeMembersInSegment" using a CRM Workflow?

    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!

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Have you tried to "IncludeMembersInSegment" using a CRM Workflow?

    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 

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,622 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans