如何在Dynamics 365中将活动(邮件,便笺等)从一个联系人转移到另一个联系人

问题描述 投票:0回答:1

由于我们内部用户之一的一些不良做法。我们需要将所有活动(邮件,便笺等)从一个联系人转移到另一个联系人。我试图通过UI来实现这一目标,但找不到解决方法。

这可能吗?我正在寻找实现此目标的任何方法,无论是CRMTool,SSIS,UI还是任何其他方法。只有管​​理员会执行此操作,因此我们不需要花哨的时间,因为一年可能需要进行4次清理一些数据。

非常感谢:)

尝试使用UI,但没有成功。

dynamics-crm microsoft-dynamics dynamics-365
1个回答
0
投票

我可以想到两种更新方法。

第一种方法是在列出所有者的活动(即所有电话)中选择视图,然后导出到Excel。这将下载一个XLSX,该XLSX的开头保留有一些隐藏的列,这些记录的ID保留在其中。然后,使用新的所有者更新所有者列(请注意复制完整的全名),然后再次导入Excel电子表格。您需要针对每种活动类型(电话,电子邮件等)重复此导出/导入步骤。因此,如果您有大量的日期,这可能是不切实际的,因为需要重复,并且可以导出的记录数最多。

另一种方法是使用某些.NET代码。当然,要执行此操作,您将需要使用Visual Studio 2019。

如果是这种情况,可以解决问题:

using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;

namespace ChangeActivitiesOwner
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = "AuthType=Office365;Url=<TODO:URL>;Username=<TODO:User>;Password=<TODO:Pass>;";
            string oldUserFullname = ""; // TODO: place here fullname for the user you want to overwrite
            string newUserFullname = ""; // TODO: place here fullname for the user you want to overwrite with

            CrmServiceClient client = new CrmServiceClient(connectionString);
            IOrganizationService service = client.OrganizationWebProxyClient != null ? client.OrganizationWebProxyClient : (IOrganizationService)client.OrganizationServiceProxy;

            QueryByAttribute qbyaOldUser = new QueryByAttribute("systemuser");
            qbyaOldUser.AddAttributeValue("fullname", oldUserFullname);
            Guid olduserid = (Guid)service.RetrieveMultiple(qbyaOldUser)[0].Attributes["systemuserid"];
            QueryByAttribute qbyaNewUser = new QueryByAttribute("systemuser");
            qbyaNewUser.AddAttributeValue("fullname", newUserFullname);
            Guid newuserid = (Guid)service.RetrieveMultiple(qbyaNewUser)[0].Attributes["systemuserid"];

            foreach (string activity in new string[]{ "task", "phonecall", "email", "fax", "appointment", "letter", "campaignresponse", "campaignactivity" }) // TODO: Add other activities as needed!!!
            {
                QueryExpression query = new QueryExpression(activity)
                {
                    ColumnSet = new ColumnSet("activityid", "ownerid")
                };
                query.Criteria.AddCondition(new ConditionExpression("ownerid", ConditionOperator.Equal, olduserid));

                foreach (Entity e in service.RetrieveMultiple(query).Entities)
                {
                    e.Attributes["ownerid"] = new EntityReference("systemuser", newuserid);
                    service.Update(e);
                }
            }
        }
    }
}

请在您的信息中填写标有“ TODO”的行。

您需要将包Microsoft.CrmSdk.CoreAssemblies,Microsoft.CrmSdk.Deployment,Microsoft.CrmSdk.Workflow,Microsoft.CrmSdk.XrmTooling.CoreAssembly,Microsoft.IdentityModel.Clients.ActiveDIrectory和Newtonsoft.Json添加到程序包,并使用.NET Framework 4.6.2。

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.