dynamics-crmmicrosoft-dynamicspower-automatedynamics-365dynamics-crm-365

Anonymize contacts without any activity interaction for the last x months


I am trying to create a scheduled power automate flow to deactivate contacts without any activity interaction (email, phone call etc) for the last X months to enforce GDPR rules. My problem is that I cannot find a way to filter these contacts. The only way that I found is like below:

enter image description here

There are more than 150000 contact records in our CRM and this will take for too long. Any ideas how I can filter them?


Solution

  • The fetchXml you need can not generated with Advanced Find, you need to write it yourself.

    Below example fetchXml show how to query contacts that has no related activity created in last 1 month. The activitypointer entity stores data about activities data(email, phone call etc.). The createdon condition is made for the date. The activityid condition is made to exclude contacts that has related activity.

    Remember to change the value per your requirement.

    <fetch>
      <entity name="contact">
        <attribute name="contactid" />
        <attribute name="fullname" />
        <link-entity name="activitypointer" from="regardingobjectid" to="contactid" link-type="outer" alias="ap">
          <filter type="and">
            <condition attribute="createdon" operator="last-x-months" value="1" />
          </filter>
        </link-entity>
        <filter type="and">
          <condition entityname="ap" attribute="activityid" operator="null" />
        </filter>
      </entity>
    </fetch>
    

    Also if you want to only check certain type activity, you can filter by activitytypecode(It is a global optionset: "activitypointer_activitytypecode") like this:

    <fetch>
      <entity name="contact">
        <attribute name="contactid" />
        <attribute name="fullname" />
        <link-entity name="activitypointer" from="regardingobjectid" to="contactid" link-type="outer" alias="ap">
            <filter type="and">
                <condition attribute="createdon" operator="last-x-months" value="1" />
                <condition attribute="activitytypecode" operator="eq" value="4204" />
            </filter>
        </link-entity>
        <filter type="and">
            <condition entityname="ap" attribute="activityid" operator="null" />
        </filter>
      </entity>
    </fetch>