在“活动指针”中不允许创建/更新方法。客户关系管理2011 [英] Create/Update method not allowed in "Activity Pointer" CRM 2011

查看:70
本文介绍了在“活动指针”中不允许创建/更新方法。客户关系管理2011的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某人拥有一个插件,可以将潜在客户的活动转移到合格的机会上。我已经在机会的创建上注册了插件,下面是代码

Am having a plugin that moves the activities of lead to opportunity on qualify. I have registered the plugin on "Create" of opportunity and the following is the code

public void Execute(IServiceProvider serviceProvider)   
{
        IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        Entity entity;

        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
        {
            entity = (Entity)context.InputParameters["Target"];

            if (entity.Attributes.Contains("originatingleadid") == false) return;
        }
        else
        {
            return;
        }

        try
        {
          //.....

            EntityReference Lead = (EntityReference)entity.Attributes["originatingleadid"];
            Guid LeadGuid = Lead.Id;
            MoveActivitiesFromLeadToOpportunity(service, LeadGuid, Opportunityid);
        }
        catch (FaultException<OrganizationServiceFault> ex)
        {
            throw new InvalidPluginExecutionException(
            "An error occurred in the plug-in.", ex);
        }
    }
 private void MoveActivitiesFromLeadToOpportunity(IOrganizationService service, Guid LeadID, Guid OpportunityID)
    {    
        ConditionExpression condition = new ConditionExpression();
        condition.AttributeName = "regardingobjectid";
        condition.Operator = ConditionOperator.Equal;
        condition.Values.Add(LeadID.ToString());
        var query = new QueryExpression("activitypointer");
        query.Criteria.AddCondition(condition);
        //query.Conditions.Add("reagrdingobjectid", ConditionOperator.Equal, theIdOfTheRelatedRecord);
        query.ColumnSet = new ColumnSet(true);

        var activities = service.RetrieveMultiple(query).Entities;
        foreach (var activity in activities)
        {
            var castedActivity = (ActivityPointer)activity;
           if (castedActivity.ActivityTypeCode == "email")
            {
                castedActivity.Id = Guid.NewGuid();
                castedActivity["regardingobjectid"] = new EntityReference("opportunity", OpportunityID);
                //service.Create(castedActivity);--->Exception thrown
                //service.Update(castedActivity);---->Tried this one too.Exception is thrown stating method not supported on "ActivityPointer"
            }


        }

有人可以阐明这一点吗?我在这里想念什么吗?谢谢

Can somebody shed light on this? Am i missing something here? Thank you

推荐答案

您需要查询确切的实体类型,因为您无法更新 activitypointer

You need to query for the exact entity type, because you can't update an activitypointer

private void MoveEmailsFromLeadToOpportunity(IOrganizationService service, Guid LeadID, Guid OpportunityID)
    {    
        ConditionExpression condition = new ConditionExpression();
        condition.AttributeName = "regardingobjectid";
        condition.Operator = ConditionOperator.Equal;
        condition.Values.Add(LeadID.ToString());
        var query = new QueryExpression("email");
        query.Criteria.AddCondition(condition);
        query.ColumnSet = new ColumnSet(true);

        var emails = service.RetrieveMultiple(query).Entities;
        foreach (var email in emails)
        {
            email["regardingobjectid"] = new EntityReference("opportunity", OpportunityID);
            service.Update(email);
        }
    }

您还可以编写一个方法,该方法将首先检索全部活动(如您已经做过的那样),在检索并根据活动类型(电子邮件,传真,...)更新每条记录后检查 ActivityTypeCode

you can also write a method that will retrieve first all the activities (as you already did) check the ActivityTypeCode after retrieve and update each single record depending on activity type (email, fax, ...)

这篇关于在“活动指针”中不允许创建/更新方法。客户关系管理2011的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆