Import Member/Contacts To A Marketing Segment

A segment in 365 for marketing app is an essential feature which lets you create a list of related contacts based on some criteria( similar to advanced find). Later it is used to target customers in a customer journey.

While you can define a criteria/search for contacts and add them in a Dynamic segment, you don’t have this facility in a “Static” Segment because contacts are manually added on a per-contact basis. hence, there should be ability to import these contacts in to a static segment. 

Now, there is no out of the box way I could find by which we can bulk update contacts into a segment, however after doing a bit digging, I found a working custom solution. 

Solution

If you look into segment entity, you will find a mysterious field named “msdyncrm_segmentmemberids” as below:

segment1

This field basically consists of the ids of the contacts in a JSON format prefixed with “crm”:

segment2

Hence, whatever contacts you manually select on the segment comes and sit in this field. So we just need to update this field with ids of the contact we want to include in this segment.

You can update this field either by WebApi or a Plugin. Its upto you how you want to design your solution. In my case I have placed button on the segment form which opens a web resource providing a flexibility to upload an excel/csv file containing these ids of the contacts which you can easily read, prepare the format of the guids(prefix with “crm”) and update using a simple web api request.

 var entity = {};
            var stringIfy = JSON.stringify(Prepared_ContactsArray);
            var entity = {};
            entity.msdyncrm_segmentmemberids = stringIfy;

            var req = new XMLHttpRequest();
            req.open("PATCH", GetGlobalContext().getClientUrl() + "/api/data/v9.1/msdyncrm_segments(" + segmentId + ")", true);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.onreadystatechange = function () {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    Xrm.Utility.closeProgressIndicator();
                    if (this.status === 204) {
                        //Success - No Return Data - Do Something
                       
                    } else {
                        //Xrm.Utility.alertDialog(this.statusText);
                    
                    }
                }
            };
            req.send(JSON.stringify(entity));
        }

I hope this helps!

Cheers!

Advertisement

Enable Custom Entities For Marketing Segment Dynamic Query

A segment in 365 for marketing app is an essential feature which lets you create a list of related contacts based on some criteria( similar to advanced find). Later it is used to target customers in a customer journey.

So when you create a new segment you have an option to create it as static or dynamic. A dynamics segment is what lets you add a query to filter contacts.

picture depicts a dynamic segment query designer

However, there is one thing that will bother you which is, it will not let you add a related custom entity to form a query ( click on add group and select union as relationship)

Solution

There is a settings available in Marketing app which will let you enable this feature for any entity in your system. To check this, go to Marketing App — > Settings Section:


Under Marketing Settings, click on advanced settings.
Now click on Customer Insights Sync under marketing setting section which will give you the list of entities on the right side with check boxes.

Enable for the entities which you need and click on publish from the header.

You might see the box is grayed out and you will not have option to enable. To enable the box you need to enable the change tracking on that entity. to do that you have to go to that entity definition and enable change tracking check box. https://docs.microsoft.com/en-us/power-platform/admin/enable-change-tracking-control-data-synchronization

Once published give it some half an hour.

Navigate to your query now and you will be able to add related entities to your query just like advanced find.

I hope this helps!