Picklist items have a display label and an internal (numeric) value. First, you need to find the value that corresponds to No
. The MetadataService
allows you to do that. First, instantiate that service:
var metaservice = new MetadataService();.
metaservice.Url = "http://localhost/mscrmservices/2007/metadataservice.asmx";
metadata.Credentials = "same as you use for the crm webservice";
Then, use this method to retrieve the value of the picklist label:
int getPicklistValueByName(string picklistName, string entityLogicalName, string logicalName, MetadataService metaService)
{
RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
attributeRequest.EntityLogicalName = entityLogicalName;
attributeRequest.LogicalName = kogicalName;
var attributeResponse = (RetrieveAttributeResponse)metaService.Execute(attributeRequest);
var picklist = (PicklistAttributeMetadata)attributeResponse.AttributeMetadata;
return picklist.Options.Where(op => op.Label.UserLocLabel.Label == picklistName).Single().Value.Value;
}
A call could looke like this:
var value = getPicklistValueByName("kez_servicecontracttype", "key_entitytype", "No", metaService)
Now, use this value in your condition expression. The alternative is to hardcode the numerical value as a constant in your program - which is better depends on your scenario.