picklist values RRS feed

  • Question


    hi all,


    I have to create new picklist attribute on the account form.I know how create picklist and add it attributes ,but I now need that picklist take values from the table.How can I do it.



    Thursday, October 16, 2008 8:27 AM


  • Hi,


    Picklist are mostly used when you have a defined set of values but for dynamic values or picking values from a table, use custom entity and add it as a lookup to your form.


    Hope this helps,


    Thursday, October 16, 2008 8:13 PM

All replies

  • Hi,


    Picklist are mostly used when you have a defined set of values but for dynamic values or picking values from a table, use custom entity and add it as a lookup to your form.


    Hope this helps,


    Thursday, October 16, 2008 8:13 PM
  • Hi Khatia,

    Yes, lookups are a good solution for allowing users to create new values at run-time. If you need to display values for a picklist for integration purposes where the values need to correspond to another system's values (e.g. Axapta), you also could host your picklist in an IFRAME on an ASPX form and save the picklist value to an nvarchar (or int) field on the MS CRM form.

    Alternately a 'cleaner' solution would be to dynamically integrate the values in the table with the lookup.


    Friday, October 17, 2008 7:03 AM
  • hi,


    thanks for reply.I exactly would like to take values from table for picklist,but I don't know how to do it.It is necesary  to write code or other.


    best regards



    Friday, October 17, 2008 9:50 AM
  • I am not an experience developer in crm, so this solutions was not so clearly form,but anyway tanks a lot.


    I will try to explain exactly what I have to do:


     have to create three new picklist field on account entity and values must be the same as ar in navision for this field.there was idea that create a table and write this values there and after this picklist take it.but I don't know how to do this.


    If lookup field is the best solution for this I will try to umderstand its context.




    Friday, October 17, 2008 10:33 AM



       If a lookup field is enough for you.It is simple.You just need to create a 1:N relationship in the Table entity to the entity which you want the lookup to be. Table entity,I mean the table that which you need to display in lookup.

    Then add the lookup field in the entity page.Thats all.

    Friday, October 17, 2008 11:39 AM
  • And here are the exact steps to do this:


    1. Go to : Settings->Customization->Customize entities.

    2. Create a new entity for your new table data.

    3. Every entity has a primary field. This field gets shown up in the lookup. Name this field appropriately.

    4. Publish this entity.

    5. Now double click any other entity, where you would want the lookup.

    6. In the left navigation pane, you'll find N:1 relationships.Create an N:1 relationship with the entity created in step 2.

    7. Now go to forms and views on the same entity. Clisk Main Form.

    8. Select 'Add fields'.

    9. Add the required lookup field.

    10. Publish the changes.

    11. Populate the entity created in step 2 with data and you are good to go.


    Monday, October 20, 2008 4:56 PM
  • Hi KhatiaG,

    Essentially you have a few options:

    1. Automatically synchronize the values from the Navision picklist with those in MSCRM.
    - This requires a fair bit of knowledge of both Navision as well as MS CRM, so perhaps not the best answer.

    2. Host your picklist in an IFRAME - Picklist gets its values from the Navision table. You merely save the picklist value to a varchar field.
    - Easier solution, but may provide an ugly front end for MSCRM

    3. Go with lookup option. Again you will need to synchronize MS CRM's values with those within Navision. Slightly easier solution as no 1 above.

    The essential question is

    * Is it feasible to manually update the values in MSCRM when those change in Navision?

    Monday, October 20, 2008 10:16 PM

    Hi Karlo,


    thanks for reply.My manager want that the picklist values update when those change in Navision.You have wrote "Picklist gets its values from the Navision table" this is exactly I want.How can I do it.



    Tuesday, October 21, 2008 11:26 AM
  • KhatiaG,


    You can try as (This only support in CRM 4.0) :




    // Create an authentication token.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    token.OrganizationName = "AdventureWorksCycle";

    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    token.AuthenticationType = 0;

    // Create the metadata Web service
    MetadataService service = new MetadataService();
    service.Url = "http://<servername>:<port>/MSCRMServices/2007/MetadataService.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    service.PreAuthenticate = true;


    Delete options from picklist


    Example for delete an option

    // Create the request.
    DeleteOptionValueRequest deleteRequest = new DeleteOptionValueRequest();

    // Set the properties for the request.
    deleteRequest.AttributeLogicalName = "statuscode";
    deleteRequest.EntityLogicalName = EntityName.contact.ToString();

    // Remove a previously inserted option.
    deleteRequest.Value = 200000;

    DeleteOptionValueResponse deleteResponse = (DeleteOptionValueResponse)metadataService.Execute(deleteRequest);



    Create options



    // Create new picklist label
    MetadataServiceSdk.CrmLabel newCrmLabel = new MetadataServiceSdk.CrmLabel();
    MetadataServiceSdk.CrmNumber langCode = new MetadataServiceSdk.CrmNumber();
    MetadataServiceSdk.LocLabel englishLabel = new MetadataServiceSdk.LocLabel();

    // Use US English lang code
    langCode.Value = 1033;
    englishLabel.LanguageCode = langCode;
    englishLabel.Label = "New Picklist Label";
    newCrmLabel.LocLabels = new MetadataServiceSdk.LocLabel[] { englishLabel };

    // Create a request.
    InsertOptionValueRequest insertRequest = new InsertOptionValueRequest();

    // Insert new label text into an existing picklist
    insertRequest.AttributeLogicalName = "address1_addresstypecode";
    insertRequest.EntityLogicalName = EntityName.contact.ToString();
    insertRequest.Label = newCrmLabel;
    insertRequest.Value = new MetadataServiceSdk.CrmNumber();

    // Microsoft CRM 4.0 picklist values start at 200,000 to maintain backwards compatibility with 3.0
    insertRequest.Value.Value = 200000;

    // Send the message.
    InsertOptionValueResponse insertResponse = (InsertOptionValueResponse)metadataService.Execute(insertRequest);


    Use this example "Create option" for each record navision table







    Tuesday, October 21, 2008 2:14 PM
  • What Malcolm said Smile

    Just to add to his post, you will probably want to do the following after creating the new entity. Publish the customization.

            private void PublishPicklistChanges(string EntityName)
                    if (m_PicklistsModified == true)
                        PublishXmlRequest request = new PublishXmlRequest();
                        request.ParameterXml = "<importexportxml>" + "<entities>" + "<entity>" + EntityName + "</entity>" + "</entities>" + "<nodes/>" + "</importexportxml>";

                        // Execute the request.
                        PublishXmlResponse response = (PublishXmlResponse)CRMServ.Execute(request);

                        // Blimey! That was a good sleep
                catch (Exception ex)
                    // Removed for clarity

    You may want to use a SQL trigger to pick up on the changes to that table, alternately run a daily/hourly routine which compares the values in the table in Navision with those in SQL and synchronises those. Alternately you could write a routine in Navision which allows a user to create the value in MS CRM when they create it in Navision.


    Wednesday, October 22, 2008 6:18 PM
  • Hi,

    This article is quite useful for me. I used InsertPicklist Option class to insert the values in the picklist. I need to set a default value while inserting the values to it. can it be possible through code?

    Thursday, July 16, 2009 7:20 AM