Plugins Crm插件更新失败
我为quote和quote product创建了两个名为“Price”的新字段,每次更新第一个字段时,我都要更新第二个字段 这是我的密码:Plugins Crm插件更新失败,plugins,dynamics-crm,crm,Plugins,Dynamics Crm,Crm,我为quote和quote product创建了两个名为“Price”的新字段,每次更新第一个字段时,我都要更新第二个字段 这是我的密码: protected void ExecutePostAccountUpdateContacts(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } string oldPric
protected void ExecutePostAccountUpdateContacts(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
string oldPrice = "";
string newPrice = "";
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
var ServiceContext = new OrganizationServiceContext(service);
ITracingService tracingService = localContext.TracingService;
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null;
// get the post entity image
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
if (preImageEntity.Attributes.Contains("Price"))
{
oldPrice = (string)preImageEntity.Attributes["Price"];
}
if (postImageEntity.Attributes.Contains("Price"))
{
newPrice = (string)postImageEntity.Attributes["Price"];
}
if (newPrice != oldPrice)
{
try
{
//Create query to get the related contacts
var res = from c in ServiceContext.CreateQuery("Products")
where c["parentQuoteid"].Equals(entity.Id)
select c;
foreach (var c in res)
{
Entity e = (Entity)c;
e["Price"] = newPrice;
ServiceContext.UpdateObject(e);
}
ServiceContext.SaveChanges();
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
}
虽然你没有问任何问题,但你的问题并不完全正确。因此,我假设您的插件在使用
parentquoteid
查询product
时失败
并非所有linq运算符都已实现,而且,还将实体逻辑名称作为参数传递给create查询,因此只需product
,而不是product
。没有名为parentquoteid
的现成字段,是否缺少自定义属性前缀
var res = from c in ServiceContext.CreateQuery("product")
where c.GetAttributeValue<Guid>("new_parentquoteid") == entity.Id
select c;
var res=来自ServiceContext.CreateQuery(“产品”)中的c
其中c.GetAttributeValue(“new_parentquoteid”)==entity.Id
选择c;