엔티티의 관련 레코드를 새로 생성 된 레코드에 연결하려고합니다. 플러그인은 생성 및 사전 작업시 트리거됩니다.어소시에이트 메서드
새로운 개체로 컬렉션을 연결하려고 할 때 오류가 발생합니다
public void Execute(IServiceProvider serviceProvider)
{
// Instanciation des services
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(null);
Entity target = (Entity)context.InputParameters["Target"];
EntityReference contrats = (EntityReference)target.Attributes["new_contratsid"];
FetchExpression fetch = new FetchExpression(@"
<fetch distinct='false' mapping='logical'>
<entity name='" + context.PrimaryEntityName + "'><link-entity name='new_contrats' 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);
// Vérification qu'il y a au moins une ligne de contrat associée
if (lines.Entities.Any())
{
var first = lines.Entities.Last();
if (first.GetAttributeValue<OptionSetValue>("statecode").Value == 1)
{
FetchExpression query = new FetchExpression(@"
<fetch distinct='false' mapping='logical'>
<entity name='incident'><filter type='and'><condition attribute='new_lignecontrat' value='"+first.Id+"' operator='eq'/></filter></entity></fetch>");
EntityCollection incident = service.RetrieveMultiple(query);
if (incident.Entities.Any())
{
foreach (var e in incident.Entities)
{
e.Attributes["new_lignecontrat"] = new EntityReference (target.LogicalName, target.Id);
}
}
}
}
: 여기
내 코드입니다 "존재하지 않는 아이디 = ad630ba6-684e-e111-92e3-00155d151905와 new_ligneContrat을"
무엇이 잘못 되었나요 ???
미리 감사드립니다.
편집 1 : ok는 아직 레코드가 존재하지 않으므로 논리적으로 보임> <. 한 가지만 : 조회 필드의 값을 어떻게 변경할 수 있습니까? 그 유형은 무엇입니까?
편집 2 : 코드를 실행할 때 오류가 발생하지 않지만 인시던트 엔티티 필드가 업데이트되지 않음> < '... 내 코드를 invalidPluginExceptions로 테스트했는데 코드 끝에 도달했습니다. 코드 업데이트 ...
accountnumberplugin.cs 투어 답변 피터 주셔서 감사합니다! 포스트 오페라에서 플러그인을 시작하는 것은 문제가되지 않습니다. 나는 실제로 1 : N 관계를 연구하고 있습니다. 실제로 필요한 것은 새로운 "new_lignecontrat"가 생성되면 인시던트 엔티티에서 이전 엔트리와 관련된 조회 필드가 업데이트됩니다. 그래서 간단합니다. e.Attributes.getValue ("new_lignecontrat") = 새로운 EntityReference (target.logicalName, target.Id); 그 일을 해? –
MademoiselleLenore
@MademoiselleLenore : 맞습니다.N : N 관계에 대해서는'Associate' 메소드를 사용하지만, 1 : N 관계에 대해서는 엔티티에'EntityReference'를 직접 할당 할 수있는 사치가 있습니다. 그러면 잘 작동합니다. –
감사합니다 피터, 그냥 내 게시물을 편집 한 이유가 작동하지 않습니다 ... – MademoiselleLenore