locked
Microsoft Dynamic CRM 2011 RRS feed

  • Question

  • Hello ,

    I am getting following error when tried to fill drop down list with account entity in ms dynamics crm through a web application.

    Thursday, March 22, 2012 12:46 PM

Answers

  • Hi

    When you are getting exception, Can you check in view details and look for Inner Exception or details for the exception.

    Please add a try catch ...
    Also, add a soap exception and generic exception.

    public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                DescriptionTable.Visible = false;
                message.Visible = false;
                CrmService service = new CrmService();
                CrmAuthenticationToken token = new CrmAuthenticationToken();
                token.AuthenticationType = 0;
                token.OrganizationName = "CRM2011";

    try {   

             MetadataService metadataService = new MetadataService();
                metadataService.Url = "http://************/MSCRMServices/2007/MetadataService.asmx";
                metadataService.CrmAuthenticationTokenValue = token;
                metadataService.Credentials = new System.Net.NetworkCredential("*****", "*******", "********");
                metadataService.PreAuthenticate = true;

                RetrieveAttributeRequest request = new RetrieveAttributeRequest();
                request.EntityLogicalName = EntityName.account.ToString();
                request.LogicalName = "new_account";

                RetrieveAttributeResponse response = (RetrieveAttributeResponse)metadataService.Execute(request);

                PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;
                foreach (Option o in picklist.Options)
                {
                    DdlAccount.Items.Add(new ListItem(o.Label.UserLocLabel.Label, o.Value.Value.ToString()));
                }

    }       

    catch (SoapException SoapExp)

    {

    }

    catch (Exception Exp)

    {

    }

    }

    In soap exception, look for Inner exception and details..

    • Edited by CRMDevlpr Thursday, March 22, 2012 1:12 PM
    • Marked as answer by DynamicsCRM31 Thursday, March 22, 2012 1:26 PM
    Thursday, March 22, 2012 1:04 PM
  • Hi,

    Have solved it..... It will "name" instead of "new_account".

    Thanks for your time.

    • Marked as answer by DynamicsCRM31 Thursday, March 22, 2012 1:26 PM
    Thursday, March 22, 2012 1:26 PM

All replies

  • Here is the code if previous image is not readable...


    public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                DescriptionTable.Visible = false;
                message.Visible = false;
                CrmService service = new CrmService();
                CrmAuthenticationToken token = new CrmAuthenticationToken();
                token.AuthenticationType = 0;
                token.OrganizationName = "CRM2011";

                MetadataService metadataService = new MetadataService();
                metadataService.Url = "http://************/MSCRMServices/2007/MetadataService.asmx";
                metadataService.CrmAuthenticationTokenValue = token;
                metadataService.Credentials = new System.Net.NetworkCredential("*****", "*******", "********");
                metadataService.PreAuthenticate = true;

                RetrieveAttributeRequest request = new RetrieveAttributeRequest();
                request.EntityLogicalName = EntityName.account.ToString();
                request.LogicalName = "new_account";

                RetrieveAttributeResponse response = (RetrieveAttributeResponse)metadataService.Execute(request);

                PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;
                foreach (Option o in picklist.Options)
                {
                    DdlAccount.Items.Add(new ListItem(o.Label.UserLocLabel.Label, o.Value.Value.ToString()));
                }
            }


    Please Help me to resolve it.

    I am getting error "Server was unable to process request." on Execute method of metadataService.

    Thursday, March 22, 2012 12:49 PM
  • Hi Milan ,

     To access Metadata  make sure that

       user you are using to authenticate has a Admin privillege

     Also try to handle Soap exception

      to get more descriptive and meaning ful error message like

    try 
    {
       queues = service.RetrieveMultiple(query);
    } 
    catch(System.Web.Services.Protocols.SoapException ex)
    {
       Console.WriteLine(ex.Message + ". " + ex.Detail.InnerText);
    }
    
    

     hth

    dkay

     if the response answered your question, please take a minute and mark the response as an answer.

    Thursday, March 22, 2012 12:57 PM
  • Hi

    When you are getting exception, Can you check in view details and look for Inner Exception or details for the exception.

    Please add a try catch ...
    Also, add a soap exception and generic exception.

    public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                DescriptionTable.Visible = false;
                message.Visible = false;
                CrmService service = new CrmService();
                CrmAuthenticationToken token = new CrmAuthenticationToken();
                token.AuthenticationType = 0;
                token.OrganizationName = "CRM2011";

    try {   

             MetadataService metadataService = new MetadataService();
                metadataService.Url = "http://************/MSCRMServices/2007/MetadataService.asmx";
                metadataService.CrmAuthenticationTokenValue = token;
                metadataService.Credentials = new System.Net.NetworkCredential("*****", "*******", "********");
                metadataService.PreAuthenticate = true;

                RetrieveAttributeRequest request = new RetrieveAttributeRequest();
                request.EntityLogicalName = EntityName.account.ToString();
                request.LogicalName = "new_account";

                RetrieveAttributeResponse response = (RetrieveAttributeResponse)metadataService.Execute(request);

                PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;
                foreach (Option o in picklist.Options)
                {
                    DdlAccount.Items.Add(new ListItem(o.Label.UserLocLabel.Label, o.Value.Value.ToString()));
                }

    }       

    catch (SoapException SoapExp)

    {

    }

    catch (Exception Exp)

    {

    }

    }

    In soap exception, look for Inner exception and details..

    • Edited by CRMDevlpr Thursday, March 22, 2012 1:12 PM
    • Marked as answer by DynamicsCRM31 Thursday, March 22, 2012 1:26 PM
    Thursday, March 22, 2012 1:04 PM
  • Hi,

    I have seen the detail exception. Its saying that  request.LogicalName = "new_account"; is invalid.

    I want to know what will be there if i want to use account entity.

    Thursday, March 22, 2012 1:17 PM
  • Hi,

    Have solved it..... It will "name" instead of "new_account".

    Thanks for your time.

    • Marked as answer by DynamicsCRM31 Thursday, March 22, 2012 1:26 PM
    Thursday, March 22, 2012 1:26 PM
  • Hi,

    Now its throwing error in next line..

    Error is

    "Unable to cast object of type 'Microsoft.Crm.Sdk.Metadata.StringAttributeMetadata' to type 'Microsoft.Crm.Sdk.Metadata.PicklistAttributeMetadata'."

    Please help me out.

    Thursday, March 22, 2012 1:29 PM
  • Hi Milan ,

    In what way is the answer is different from the marked Answer ,

     -------------------------------------------------------------------------------
    If my post was a answer your question, could please mark it aswell as Answer.
    --------------------------------------------------------------------------------

    thanks

    Dkay


    • Edited by D kay Thursday, March 22, 2012 9:02 PM
    Thursday, March 22, 2012 2:23 PM