【发布时间】:2011-12-21 16:10:14
【问题描述】:
(不,又不是法国女孩!!!)
所以...我有两个具有 n-n 关系的实体:“new_produit”和“new_lignecontrat”。 我需要将最后一个“new_lignecontrat”记录的“new_produit”记录复制到新创建的“new_lignecontrat”中。
插件在为 new_lignecontrat 创建时触发。
到目前为止,我已经写了这个,但我不太确定复制“new_produit”记录要遵循的步骤......
else if (modeleContrat.Id.Equals (ContratForfaitaire))
{
FetchExpression fetch = new FetchExpression(@"
<fetch distinct='false' mapping='logical'>
<entity name='new_contrats'><link-entity name='" + context.PrimaryEntityName + "' alias='nombreligne' from='new_contratsid' to='new_contratsid'><filter type='and'><condition attribute='new_contratsid' value='" + contrats.Id + "' operator='eq'></condition></filter></link-entity></entity></fetch>");
EntityCollection lines = service.RetrieveMultiple(fetch);
if (lines.Entities.Any())
{
var last = lines.Entities.Last();
if (last.GetAttributeValue<OptionSetValue>("statecode").Value == 1)
{
QueryExpression query = new QueryExpression();
query.EntityName = "new_produit";
query.ColumnSet = new ColumnSet("new_produitid");
Relationship relationship = new Relationship();
// name of relationship between team & systemuser
relationship.SchemaName = "new_new_lignecontrat_new_produit";
RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection();
relatedEntity.Add(relationship, query);
RetrieveRequest request = new RetrieveRequest();
request.RelatedEntitiesQuery = relatedEntity;
request.ColumnSet = new ColumnSet("new_lignecontratid");
request.Target = new EntityReference
{
Id = last.Id,
LogicalName = last.LogicalName
};
RetrieveResponse response = (RetrieveResponse)service.Execute(request);
if (((DataCollection<Relationship, EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities)))).Contains(new Relationship("new_new_lignecontrat_new_produit")) && ((DataCollection<Relationship, EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities))))[new Relationship("new_new_lignecontrat_new_produit")].Entities.Count > 0)
{
response.Entity.Attributes.Remove("new_produitid");
response["new_lignecontratid"] = new EntityReference(target.LogicalName, target.Id);
【问题讨论】:
-
身为法国女孩不是不接受答案的借口;)
-
哎呀...我完全忘了接受答案...对不起>
-
您已经解决了问题,无需道歉 :)
标签: c# plugins dynamics-crm-2011