locked
How to create incident using mscrm 2011 sdk RRS feed

  • Question

  • I want to create a record in mscrm 2011 using sdk.I have a aspx form where are fill some fields and when i click the create button,it should create the record in mscrm 2011.I have an onpremise system.I added the microsoft.xrm.sdk.dll ,microsoft.crm.sdk.proxy.dll from the bin folder of the mscrm 2011 sdk and used the below code but it does not work.

    I get the error message:You should specify a parent contact or account.

    I have given hard coded the accountid

    Am i doing something wrong??

    public void CreateIncidentNew(string strAccountId)
        {
            ClientCredentials Credentials = new ClientCredentials();
            Credentials.UserName.UserName = "";
            Credentials.UserName.Password = "";
            Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            CredentialCache.DefaultNetworkCredentials.Domain = "" ;
            CredentialCache.DefaultNetworkCredentials.UserName = "";
            CredentialCache.DefaultNetworkCredentials.Password = "";
          
            Uri OrganizationUri = new Uri("");
         
            Uri HomeRealmUri = null;

            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
            {
                //serviceProxy.EnableProxyTypes();
                IOrganizationService service = (IOrganizationService)serviceProxy;

                Entity newincident = new Entity("incident");

                //newincident.Attributes.Add("title", txt_title.Text);
                newincident["accountid"] = "91C86912-6951-E011-AB71-7071BCA7FDE9";
                newincident["title"] = txt_title.Text.ToString();


               // newincident.Attributes.Add("new_description", txt_casedesc.Text);
                newincident["new_description"] = txt_title.Text.ToString();
                try
                {
                    Guid incidentGuid = service.Create(newincident);
                }
               
                catch (System.Web.Services.Protocols.SoapException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }

        }

    Please let me know the steps.


    • Edited by MSCRM007 Wednesday, August 1, 2012 8:05 AM
    Wednesday, August 1, 2012 8:04 AM

Answers

  • Hi,

    you have to set customer (customerid) while creating case entity record.

    refer: http://msdn.microsoft.com/en-us/library/gg328170.aspx

    try

    EntityReference _customerid= new EntityReference("account", new Guid("91C86912-6951-E011-AB71-7071BCA7FDE9")); 
    newincident["customerid"] = _customerid;


    Conatact Me
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, August 1, 2012 8:21 AM
    Moderator

All replies

  • Hi,

    you have to set customer (customerid) while creating case entity record.

    refer: http://msdn.microsoft.com/en-us/library/gg328170.aspx

    try

    EntityReference _customerid= new EntityReference("account", new Guid("91C86912-6951-E011-AB71-7071BCA7FDE9")); 
    newincident["customerid"] = _customerid;


    Conatact Me
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, August 1, 2012 8:21 AM
    Moderator
  • Thank you so much...It worked:)
    Wednesday, August 1, 2012 8:29 AM