Within Dynamics CRM the Lead entity has both a Status and a Status Reason. Using the API I can get all of the Status Reasons. Where I am getting tripped up is when my user selects a Status Reason I would like to work backwards and figure out which Status is associated with the selected Status Reason.
Here is how I get all of the Status Reasons:
//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());
}
And To update an entity I am just using LINQ:
//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();
I just can’t figure out how to query CRM to figure out what value I would need to put in for the ???
You can retrieve the information for state with status.