简体   繁体   English

无法从CRM 2011插件中的活动中检索第三个实体

[英]Can not retrieve Third entity from a avtivity in crm 2011 Plugin

I'm working on a crm plug in for sending sms. 我正在开发用于发送短信的crm插件。

i have 3 entity in my solution. 我的解决方案中有3个实体。

first : Activity Entity. 首先:活动实体。 this is main entity and user can send sms to multiple contact using this entity. 这是主要实体,用户可以使用此实体向多个联系人发送短信。 (ppp_sms)

Second: A non activity entity for saving configuration like username and password. 第二:非活动实体,用于保存用户名和密码之类的配置。 ppp_smsconfiguration

Third:Another non activity entity for saving sms result. 第三:另一个保存短信结果的非活动实体。 i want to save sms(s), one by one for saving result(s). 我想一次保存短信,以保存结果。 for example: if user send a sms to 3 contact, he or she should open first Entity, choose the 3 contact, write the message and send it. 例如:如果用户向3个联系人发送短信,则他或她应打开第一个实体,选择3个联系人,编写消息并发送。 after sending system will create 3 record in third entity, each record for each contact. 发送系统后,将在第三个实体中创建3条记录,每个记录用于每个联系人。

and my problem is: i can retrieve first and second entity information and i can' not retrieve the third entity information. 我的问题是:我可以检索第一和第二实体信息,而我不能检索第三实体信息。

this is my whole code: i can not retrieve ppp_sentsms entity information 这是我的整个代码:我无法检索ppp_sentsms实体信息

public void Execute(IServiceProvider serviceProvider)
{
    if (serviceProvider == null)
    {
        throw new ArgumentNullException("serviceProvider");
    }

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = factory.CreateOrganizationService(new Guid?(context.InitiatingUserId));
    ITracingService service2 = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    QueryExpression expression = new QueryExpression("ppp_smsconfiguration");
    expression.PageInfo.ReturnTotalRecordCount = true;
    ColumnSet set = new ColumnSet();
    set.AllColumns = true;
    expression.ColumnSet = set;
    EntityCollection entitys = service.RetrieveMultiple(expression);

    QueryExpression expression1 = new QueryExpression("ppp_sentsms");
    expression1.PageInfo.ReturnTotalRecordCount = true;
    ColumnSet setSentSMS = new ColumnSet();
    setSentSMS.AllColumns = true;
    expression1.ColumnSet = setSentSMS;
    EntityCollection entitys1 = service.RetrieveMultiple(expression1);

    throw new Exception(entitys1.TotalRecordCount.ToString());

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

        Entity entity2 = (Entity)context.InputParameters["Target"];

       // Entity preEntity = (Entity)context.PreEntityImages["PreImage"];

        this.dbMobileNo.Clear();

        this.dbTo.Clear();
        this.dbMessage = "";

        if (entity2.LogicalName == "ppp_sms")
        {
            QueryExpression expression3 = new QueryExpression("ppp_sms");
            ColumnSet set2 = new ColumnSet();
            set2.AllColumns = true;
            expression3.ColumnSet = set2;
            ConditionExpression item = new ConditionExpression();
            item.AttributeName = "activityid";
            this.CurrentSmsGuid = (Guid)entity2.Attributes["activityid"];
            item.Values.Add(this.CurrentSmsGuid);
            FilterExpression expression5 = new FilterExpression();

            expression5.Conditions.Add(item);
            expression3.Criteria = expression5;
            EntityCollection entitys2 = service.RetrieveMultiple(expression3);
        }
    }
}

is that a plugin that is running pre or post creation? 是在创建之前或之后运行的插件吗? I suggest you to go on early bound if the query expression are driving you insane. 如果查询表达式使您发疯,我建议您早日进行。 Remember that sometimes, if the plugin is running in pre creation, you will never be able to retrieve the entities, especially if is running sychronously. 请记住,有时,如果插件在预创建中运行,则您将永远无法检索实体,尤其是在同步运行时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM