2012-04-10 9 views
2

Innerhalb von Dynamics CRM hat die Lead-Entität sowohl einen Status als auch einen Statusgrund. Mit der API kann ich alle Status-Gründe erhalten. Wo ich gestolpert bin, wenn mein Benutzer einen Statusgrund auswählt, möchte ich rückwärts arbeiten und herausfinden, welcher Status dem ausgewählten Statusgrund zugeordnet ist.Abrufen eines Leads "Status" aus einem Leads- "Statusgrund"

Hier ist, wie ich alle Status Gründe erhalten:

//get the list of status reasons 
RetrieveAttributeRequest request = new RetrieveAttributeRequest(); 
request.EntityLogicalName = "lead"; 
request.LogicalName = "statuscode"; 

RetrieveAttributeResponse response = RetrieveAttributeResponse)theOrgContext.Execute(request); 
StatusAttributeMetadata picklist = (StatusAttributeMetadata)response.AttributeMetadata; 
foreach (OptionMetadata option in picklist.OptionSet.Options) 
{ 
    retval.ListOfStatuses.Add(option.Value.Value, option.Label.UserLocalizedLabel.Label.ToString()); 
} 

Und eine Entität aktualisieren ich nur LINQ bin mit:

//set the status to the new value 
theLead.StatusCode.Value = int.Parse(statusValue); 

theLead.StateCode = ??? 

//mark the object as updated 
theContext.UpdateObject(theLead); 

//persist the changes back to the CRM system 
theContext.SaveChanges(); 

Ich kann einfach nicht herausfinden, wie die Abfrage CRM, um herauszufinden, welchen Wert ich für die ???

+0

Bevor jemand fragt, erlauben wir dem Kunden, mehr als nur die Standardstatusgründe für einen bestimmten Status hinzuzufügen. Daher kann ich die Enumerationen, die mit den LINQ-Entitäten geliefert werden, nicht verwenden. –

Antwort

3

Sie können die Informationen für Status mit Status abrufen.

RetrieveAttributeRequest req = new RetrieveAttributeRequest(); 
req.EntityLogicalName = "lead"; 
req.LogicalName = "statuscode"; 
req.RetrieveAsIfPublished = true; 
RetrieveAttributeResponse res = (RetrieveAttributeResponse)yourContext.Execute(req); 

StatusAttributeMetadata attribute = (StatusAttributeMetadata)res.AttributeMetadata; 
foreach (StatusOptionMetadata oStatusOptionMetaData in attribute.OptionSet.Options) 
{ 
    var state = oStatusOptionMetaData.State.Value; 
    var status = oStatusOptionMetaData.Value.Value; 
} 
Verwandte Themen