2017-10-29 1 views
0

Ich habe eine Kontonummer und möchte die Sammlung von Kontakten unter dem Konto abrufen, um eine E-Mail-Liste zu erstellen.Wie Sie alle Kontakte eines Kontos erhalten und eine E-Mail-Liste in MS Dynamics CRM erstellen?


//build up Email 
    private Email BuildEmail(ActivityParty allcontacts){.... build my emailhere} 

    private List<Entity> GetAllContactsFromAccountId(Guid accountId, List<Entity> toList) 
    {   

     //how can I get all the contacts here 
     foreach (Entity contact in Account.Contact.Entities)//???? 
     { 
      Entity activityParty = new Entity("activityparty"); 
      activityParty["partyid"] = new EntityReference("??", e.Id); 

      if (toList.Any(t => t.GetAttributeValue<EntityReference>("partyid").Id == e.Id)) continue; 

      toList.Add(activityParty); 
     } 

     return toList; 
    } 

Antwort

0

Sie können die Kontoschlüssel "parentcustomerid" in Kontakt Einheit finden. Sie können Kontaktsammlung nach Konto-ID wie unten erhalten.

private EntityCollection getContactByAccountId(IOrganizationService service, Guid accountId) 
    { 
     QueryExpression query = new QueryExpression("contact"); 
     query.ColumnSet = new ColumnSet(new string[] { "contactid", "fullname" }); 
     query.Criteria.AddCondition(new ConditionExpression("parentcustomerid", ConditionOperator.Equal, accountId)) 
     return service.RetrieveMultiple(query); 
    } 
+0

danke für die Antwort, aber es gibt mir Konvertierungsfehler. Für z.B. Wann, gebe ich dies als entitycollection in einem benutzerdefinierten Workflow zu TargetOutput ref ... ("Kontakt") Ich bekomme und Fehler kann nicht umgewandelt werden "entitycollection" zu "entityreference" – transformer

+0

Ich denke, Sie können Out Put Parameter von EntityCollection-Typ verwenden. wie [Output ("Kontakte")] [ReferenceTarget ("contact")] public OutArgument Kontakte {get; einstellen; }. Und offensichtlich können Sie EntityCollection-Objekt nicht auf eine EntityReference festlegen. –

Verwandte Themen