我正在开发用于发送短信的 crm 插件。
我的解决方案中有 3 个实体。
第一个:活动实体。这是主要实体,用户可以使用此实体向多个联系人发送短信。(ppp_sms)
第二:用于保存用户名和密码等配置的非活动实体。ppp_smsconfiguration
第三:另一个用于保存短信结果的非活动实体。我想保存短信,一一保存结果。例如:如果用户向3个联系人发送短信,他或她应该打开第一个实体,选择3个联系人,编写消息并发送。发送后系统将在第三个实体中创建 3 条记录,每个联系人的每条记录。
我的问题是:我可以检索第一个和第二个实体信息,而我不能检索第三个实体信息。
这是我的全部代码:我无法检索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);
}
}
}