MSDN > Home page del forum > Data Mining > creating primary keys in microsoft dynamics crm
Formula una domandaFormula una domanda
 

Con rispostacreating primary keys in microsoft dynamics crm

Risposte

  • lunedì 29 giugno 2009 10.49Scott Sewell, CustomerEffectiveMVPMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    The unique key is automatically created for you when you create a custom entity - new_customentitynameID - it's a guid. -

    Adding other attributes is done through the CRU administration UI.
    Scott Sewell, CustomerEffective | http:\\blog.CustomerEffective.com | Twitter:@ScottSewell
    • Contrassegnato come rispostaprincess_me lunedì 29 giugno 2009 14.25
    •  

Tutte le risposte

  • lunedì 29 giugno 2009 10.49Scott Sewell, CustomerEffectiveMVPMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    The unique key is automatically created for you when you create a custom entity - new_customentitynameID - it's a guid. -

    Adding other attributes is done through the CRU administration UI.
    Scott Sewell, CustomerEffective | http:\\blog.CustomerEffective.com | Twitter:@ScottSewell
    • Contrassegnato come rispostaprincess_me lunedì 29 giugno 2009 14.25
    •  
  • lunedì 29 giugno 2009 11.30princess_me Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Contiene codice
    thanks.. that was of great help.... I wanted to know how to access crm web services from an aspx page... i tried to execute the following code given as example in the crmsdk.chm file

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Win32;
    namespace WebApplication20
    {
        public partial class _Default : System.Web.UI.Page
        {
            public string orgname;
            public string crmurl;
            public string metaurl;
            public bool offline;
    
            protected void Page_Load(object sender, EventArgs e)
            {
                #region CRM URLs and Organization Name
    
                //Determine Offline State from Host Name
                Response.Write(Request.Url.Host.ToString());
                if (Request.Url.Host.ToString() == "127.0.0.1")
                {
                    offline = true;
    
                    //Retrieve the Port and OrgName from the Registry
                    RegistryKey regkey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\MSCRMClient");
                    orgname = regkey.GetValue("ClientAuthOrganizationName").ToString();
                    string portnumber = regkey.GetValue("CassiniPort").ToString();
    
                    //Construct the URLs
                    string baseurl = "http://localhost:" + portnumber + "/mscrmservices/2007/";
                    crmurl = baseurl + "crmservice.asmx";
                    metaurl = baseurl + "metadataservice.asmx";
                }
                else
                {
                    offline = false;
    
                    //Retrieve the URLs from the Registry
                    RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
                    string ServerUrl = regkey.GetValue("ServerUrl").ToString();
                    crmurl = ServerUrl + "/2007/crmservice.asmx";
                    metaurl = ServerUrl + "/2007/metadataservice.asmx";
                   
                    //Retrieve the Query String from the current URL
                    if (Request.QueryString["orgname"] == null)
                    {
                        orgname = string.Empty;
                    }
                    else
                    {
                        //Query String
                        string orgquerystring = Request.QueryString["orgname"].ToString();
                        if (string.IsNullOrEmpty(orgquerystring))
                        {
                            orgname = string.Empty;
                        }
                        else
                        {
                            orgname = orgquerystring;
                        }
                    }
    
                    if (string.IsNullOrEmpty(orgname))
                    {
                        //Windows Auth URL
                        if (Request.Url.Segments[2].TrimEnd('/').ToLower() == "isv")
                        {
                            orgname = Request.Url.Segments[1].TrimEnd('/').ToLower();
                        }
    
                        //IFD URL
                        if (string.IsNullOrEmpty(orgname))
                        {
                            string url = Request.Url.ToString().ToLower();
                            int start = url.IndexOf("://") + 3;
                            orgname = url.Substring(start, url.IndexOf(".") - start);
                        }
                    }
                }
    
                #endregion
    
                using (new CrmImpersonator())
                {
                    CrmAuthenticationToken token;
                    if (offline == true)
                    {
                        token = new CrmAuthenticationToken();
                    }
                    else
                    {
                        // Notice that the Context parameter value is Page.Context.
                        token = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgname);
                    }
                    token.OrganizationName = orgname;
                    token.AuthenticationType = 0;
    
                    //Create the Service
                    CrmService service = new CrmService();
                    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    service.CrmAuthenticationTokenValue = token;
                    service.Url = crmurl;
    
                    // This code shows how to create the metadata service.
                    // It is not used in this sample.
                    //MetadataService meta = new MetadataService();
                    //meta.CrmAuthenticationTokenValue = token;
                    //meta.Credentials = CredentialCache.DefaultCredentials;
                    //meta.Url = "http://localhost/mscrmservices/2007/MetadataService.asmx";
    
    
                    account account = new account();
                    account.name = "Offline Impersonator: " + DateTime.Now.TimeOfDay.ToString();
                    if (offline == false)
                        // Explicitly set the owner ID for the record if not offline.
                        account.ownerid = new Owner("systemuser", token.CallerId);
    
                    service.Create(account);
                }
    
                Response.Write("Done");
    
            }
        }
    }
    

    But it failed with the following error:

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: OpenThreadToken failed with hr = 1008

    Source Error:

    Line 88:             #endregion
    Line 89: 
    Line 90:             using (new CrmImpersonator())
    Line 91:             {
    Line 92:                 CrmAuthenticationToken token;

    Server Error in '/WebApplication20' Application.

    OpenThreadToken failed with hr = 1008

     

    what is the cause for this error and how do i overcome it?
  • lunedì 29 giugno 2009 14.09Scott Sewell, CustomerEffectiveMVPMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hi - Go ahead and mark the answer to your first question as answered and repost the second question in the CRM development forum. -
    Scott Sewell, CustomerEffective | http:\\blog.CustomerEffective.com | Twitter:@ScottSewell