locked
Microsoft Dynamic CRM 4.0 RRS feed

  • Question

  • Hi,

    How to get Guid of Dropdown selected value?

    Tuesday, April 3, 2012 5:59 AM

Answers

  • Hi,

    I have resolved the issue. Don't know the reason but i have removed following two lines and its getting account id in value attribute.

    Remove following two lines .....

    DdlCompany.DataSource = FgProjectList;
    DdlCompany.DataBind();


    Regards,

    Milan Hingu
    • Marked as answer by DynamicsCRM31 Tuesday, April 3, 2012 10:37 AM
    Tuesday, April 3, 2012 10:37 AM

All replies

  • Hi Milan,

    In CRM drop down selected values always work on numbers which you give while setting them.

    In case you are interested in GUID. Run the following 2 queries. I am running for CRM 2011 as I am currently working in that version. You can search for its equivalent in CRM 4.0.

    select OptionSetId , * from MetadataSchema.OptionSet where Name like '%<<drop down name>>%'

    Copy this OptionSetId = ''

    select * from MetadataSchema.AttributePicklistValue where OptionSetId = ''

    The above will give you drop down.

    If you want the GUID in CRM through code, run your code against these in database.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.


    Ashish Mahajan, CRM Developer, CSG (Melbourne)
    My Personal Website: http://www.ashishmahajan.com
    My Blogs: http://ashishmahajancrm.blogspot.com.au and http://ashishmahajancrm.wordpress.com
    My Youtube Channel: http://www.youtube.com/user/ashishmahajanmscrm

    My Linkedin: View Ashish Mahajan's profile on LinkedIn
    My Twitter: https://twitter.com/#!/ashishmahajan74

    Tuesday, April 3, 2012 6:08 AM
  • Hi Aashish,

    I didn't find table MetadataSchema.OptionSet in database...

    i have populated my dropdown with account entity.. How can i get and set that dropdown selected value in my custom entity?

    Tuesday, April 3, 2012 6:30 AM
  • Hi Aashish,

    I am going nearer to the problem.

    I have bounded my drop down with account entity through below code..

    ColumnSet cols = new ColumnSet();
                cols.Attributes = new string[] { "name", "accountid" };
    
                QueryExpression query = new QueryExpression();
                query.EntityName = EntityName.account.ToString();
                query.ColumnSet = cols;
    
                BusinessEntityCollection accounts = service.RetrieveMultiple(query);
    
                for (int i = 0; i < accounts.BusinessEntities.Length; i++)
                {
                    account fgaccount = (account)accounts.BusinessEntities[i];
                    FgProjectList.Add(new ListItem(fgaccount.name.ToString(),fgaccount.accountid.Value.ToString()));
                    DdlCompany.Attributes.Add(fgaccount.accountid.Value.ToString(), fgaccount.name.ToString());
                }
    
                DdlCompany.DataSource = FgProjectList;
                DdlCompany.DataBind();

    And i am getting 'name' of account entity filled to the dropdown. So when i save dropdown selected value it is getting account name instead of accountid (Guid of account).

    How can i bind dropdown with account name and pass account id as selected value?


    Tuesday, April 3, 2012 7:11 AM
  • If i change code to..

    FgProjectList.Add(new ListItem(fgaccount.accountid.Value.ToString(),fgaccount.name.ToString()));

    Then it will bind dropdown with accountid (Guid of account entity), but it should be account name instead of id in dropdown.. What can be done in this?

    Tuesday, April 3, 2012 7:22 AM
  • but since dropdown.selectedvalue is string value (account name) then it will give error that invalid Guid when setting its value in below code..

    LookupProperty companyId = new LookupProperty();
            companyId.Name = "new_companyid";
            companyId.Value = new Lookup();//new Lookup("new_fgproject", new Guid(DdlCompany.SelectedValue));
            companyId.Value.name = DdlCompany.SelectedItem.Text;
            companyId.Value.Value = new Guid(DdlCompany.SelectedValue);

    How can i display dropdown with account name and save account id as its selected value ?

    Tuesday, April 3, 2012 7:25 AM
  • Hi,

    I have resolved the issue. Don't know the reason but i have removed following two lines and its getting account id in value attribute.

    Remove following two lines .....

    DdlCompany.DataSource = FgProjectList;
    DdlCompany.DataBind();


    Regards,

    Milan Hingu
    • Marked as answer by DynamicsCRM31 Tuesday, April 3, 2012 10:37 AM
    Tuesday, April 3, 2012 10:37 AM