Question : Getting (and setting) text values from a CRM Pick List?

I have a pick list in CRM (4.0) that I want to get and set text values from on an entity.

Let's say the pick list has these values:
Ejerbolig
Andelsbolig
Lejebolig
Andet

How do I read these values from the list using the enity attribute containing one of these values? (C#)

E.g.

Entity: House
Attribute: boligform = Andelsbolig

How do I read the text value (not the index number) and how do I set the value for a new entity (using the original attribute value)? (2 questions)

Answer : Getting (and setting) text values from a CRM Pick List?

No you can not.

You have to set it via index, the text is optional not the index.

You can do it by : 

crmForm.all.picklist.DataValue = 1; //Any index number valid for a given picklist.

Also how you want to read these values from C# or you need to read the values on Form at clientside only?

crmForm.all.picklist.Options will give you the list of all the picklists then you can loop through to process the values.

If you need it on server side via C# see the code snippet below

Regards,
Chinmay

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
/// <summary>
		/// Retrieves the picklist metadata from CRM
		/// </summary>
		/// <param name="attributeSchemaName">Attribute Schema name</param>
		/// <param name="entityName">Entity Name</param>
		/// <returns>Picklist Attribute Metadata</returns>
		public static CrmSdk.Metadata.PicklistAttributeMetadata GetPickList(
				string attributeSchemaName,
				string entityName )
		{
			CrmSdk.Metadata.PicklistAttributeMetadata listData;
			CrmSdkTypeProxy.Metadata.RetrieveAttributeRequest attributeRequest = new CrmSdkTypeProxy.Metadata.RetrieveAttributeRequest();
			ExtendedService.ExtendedMetadataService metaDataService = null;

			attributeRequest.EntityLogicalName = entityName;
			attributeRequest.LogicalName = attributeSchemaName;
			attributeRequest.RetrieveAsIfPublished = true;

			try
			{
				metaDataService = Services.GetCrmMetadataService();// Get an instance of CrmMetadata Service
				CrmSdkTypeProxy.Metadata.RetrieveAttributeResponse attributeResponse = (CrmSdkTypeProxy.Metadata.RetrieveAttributeResponse)metaDataService.Execute( attributeRequest );
				listData = attributeResponse.AttributeMetadata as CrmSdk.Metadata.PicklistAttributeMetadata;
			}
			
			catch( Exception exception )
			{
				//Handle Exceptions
			}


			return listData;
		}
Random Solutions  
 
programming4us programming4us