Dynamics CRM 查询表达式
Dynamics CRM QueryExpression
我有这个查询,它使用来自工作订单帐户的备注(2 种不同类型)填充工作订单。我遇到的问题是它适用于大多数工作订单,但我注意到有些工作订单没有填充注释。在我看来,帐户实体和内部注释是一对多的关系,但是我一定是错了。我还在 FetchXML 下面找到了我的查询模型。
private void PopulateInternalNotes()
{
EntityReference accountId = _Entity.GetAttributeValue<EntityReference>("hc_account");
EntityReference buisnessId = _Entity.GetAttributeValue<EntityReference>("hc_businessunit");
if(accountId == null || buisnessId ==null)
{
return;
}
_tracer.Trace("buisness unit: " + buisnessId);
//to get internal description
QueryExpression exp = new QueryExpression("hc_internalnote");
exp.Criteria.AddCondition("hc_internalnotetype", ConditionOperator.Equal, 948050000); // internal description option
exp.Criteria.AddCondition("hc_account", ConditionOperator.Equal, accountId.Id);// matches account on joborder
exp.Criteria.AddCondition("hc_businessunit", ConditionOperator.Equal, buisnessId.Id);//matches buisnessunit on joborder
exp.ColumnSet = new ColumnSet("hc_note");
EntityCollection results = _service.RetrieveMultiple(exp);
if (results.Entities.Count == 1)
{
foreach (Entity r in results.Entities)
{
_tracer.Trace("one internal desc found");
_Entity["hc_internaldescription"] = r.GetAttributeValue<string>("hc_note");
}
}
else
{
_tracer.Trace("no internal desc found");
}
//to get submission process note
QueryExpression sub = new QueryExpression("hc_internalnote");
sub.Criteria.AddCondition("hc_internalnotetype", ConditionOperator.Equal, 948050002); // submission process option
sub.Criteria.AddCondition("hc_account", ConditionOperator.Equal, accountId.Id);// matches account on joborder
sub.Criteria.AddCondition("hc_businessunit", ConditionOperator.Equal, buisnessId.Id);//matches buisnessunit on joborder
sub.ColumnSet = new ColumnSet("hc_note");
EntityCollection Subresults = _service.RetrieveMultiple(sub);
if (Subresults.Entities.Count == 1)
{
foreach (Entity s in Subresults.Entities)
{
_tracer.Trace("one submission desc found");
_Entity["hc_submissionprocessnotes"] = s.GetAttributeValue<string>("hc_note");
}
}
else
{
_tracer.Trace("more than one submission note found");
}
}
下面是 FetchXML
<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">
<entity name="hc_internalnote">
<attribute name="createdon"/>
<attribute name="statecode"/>
<attribute name="ownerid"/>
<attribute name="hc_note"/>
<attribute name="modifiedon"/>
<attribute name="modifiedby"/>
<attribute name="hc_internalnotetype"/>
<attribute name="createdby"/>
<attribute name="hc_contract"/>
<attribute name="hc_businessunit"/>
<attribute name="hc_account"/>
<attribute name="hc_internalnoteid"/>
<order descending="false" attribute="createdon"/>
<filter type="and">
<condition attribute="hc_account" value="{B1F13E37-2D34-E411-9518-005056010301}" uitype="account" uiname="Community Memorial Hospital (050394)" operator="eq"/>
</filter>
</entity>
</fetch>
来自评论:
似乎有效。问题出在我们的插件关闭期间迁移的旧记录,因此它们没有填充。
我有这个查询,它使用来自工作订单帐户的备注(2 种不同类型)填充工作订单。我遇到的问题是它适用于大多数工作订单,但我注意到有些工作订单没有填充注释。在我看来,帐户实体和内部注释是一对多的关系,但是我一定是错了。我还在 FetchXML 下面找到了我的查询模型。
private void PopulateInternalNotes()
{
EntityReference accountId = _Entity.GetAttributeValue<EntityReference>("hc_account");
EntityReference buisnessId = _Entity.GetAttributeValue<EntityReference>("hc_businessunit");
if(accountId == null || buisnessId ==null)
{
return;
}
_tracer.Trace("buisness unit: " + buisnessId);
//to get internal description
QueryExpression exp = new QueryExpression("hc_internalnote");
exp.Criteria.AddCondition("hc_internalnotetype", ConditionOperator.Equal, 948050000); // internal description option
exp.Criteria.AddCondition("hc_account", ConditionOperator.Equal, accountId.Id);// matches account on joborder
exp.Criteria.AddCondition("hc_businessunit", ConditionOperator.Equal, buisnessId.Id);//matches buisnessunit on joborder
exp.ColumnSet = new ColumnSet("hc_note");
EntityCollection results = _service.RetrieveMultiple(exp);
if (results.Entities.Count == 1)
{
foreach (Entity r in results.Entities)
{
_tracer.Trace("one internal desc found");
_Entity["hc_internaldescription"] = r.GetAttributeValue<string>("hc_note");
}
}
else
{
_tracer.Trace("no internal desc found");
}
//to get submission process note
QueryExpression sub = new QueryExpression("hc_internalnote");
sub.Criteria.AddCondition("hc_internalnotetype", ConditionOperator.Equal, 948050002); // submission process option
sub.Criteria.AddCondition("hc_account", ConditionOperator.Equal, accountId.Id);// matches account on joborder
sub.Criteria.AddCondition("hc_businessunit", ConditionOperator.Equal, buisnessId.Id);//matches buisnessunit on joborder
sub.ColumnSet = new ColumnSet("hc_note");
EntityCollection Subresults = _service.RetrieveMultiple(sub);
if (Subresults.Entities.Count == 1)
{
foreach (Entity s in Subresults.Entities)
{
_tracer.Trace("one submission desc found");
_Entity["hc_submissionprocessnotes"] = s.GetAttributeValue<string>("hc_note");
}
}
else
{
_tracer.Trace("more than one submission note found");
}
}
下面是 FetchXML
<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">
<entity name="hc_internalnote">
<attribute name="createdon"/>
<attribute name="statecode"/>
<attribute name="ownerid"/>
<attribute name="hc_note"/>
<attribute name="modifiedon"/>
<attribute name="modifiedby"/>
<attribute name="hc_internalnotetype"/>
<attribute name="createdby"/>
<attribute name="hc_contract"/>
<attribute name="hc_businessunit"/>
<attribute name="hc_account"/>
<attribute name="hc_internalnoteid"/>
<order descending="false" attribute="createdon"/>
<filter type="and">
<condition attribute="hc_account" value="{B1F13E37-2D34-E411-9518-005056010301}" uitype="account" uiname="Community Memorial Hospital (050394)" operator="eq"/>
</filter>
</entity>
</fetch>
来自评论:
似乎有效。问题出在我们的插件关闭期间迁移的旧记录,因此它们没有填充。