Set CRM 2011 field values to a new record form using url parameters

Posted: October 2, 2012 in CRM 2011, Jscripts

Set field values to new account record by passing url parameters using jscript

If you want to open a new crm record and set the field values, you can use the URL parameters.
In my example i’m using account entity. Here is the jscript code below.

 function CopyAccount() {
    var extRaqs = "";
    // populates Single Line of Text
    extRaqs += "&name=" + Xrm.Page.getAttribute("name").getValue();

    // populates Lookup field
    if (Xrm.Page.getAttribute("primarycontactid").getValue() != null) {
        var parentContact = Xrm.Page.getAttribute("primarycontactid");
        extRaqs += "&primarycontactid=" + parentContact.getValue()[0].id;
        extRaqs += "&primarycontactidname=" + parentContact.getValue()[0].name;

    // populates Optionset field
    if (Xrm.Page.getAttribute("address1_addresstypecode").getValue() != null) {
        var addressType = Xrm.Page.getAttribute("address1_addresstypecode");
        extRaqs += "&address1_addresstypecode=" + addressType.getValue();

    // populates boolean field
    if (Xrm.Page.getAttribute("creditonhold").getValue() != null) {
        var creditOnHold = Xrm.Page.getAttribute("creditonhold");
        extRaqs += "&creditonhold=" + creditOnHold.getValue();

    // gets the server url and concat with your entity name
    var serverUrl = window.parent.Xrm.Page.context.getServerUrl() + "/main.aspx?etn=account&pagetype=entityrecord&extraqs=";
    serverUrl += encodeURIComponent(extRaqs);, "_blank");
  1. Swathi says:

    Thanks for sharing this.But after clicking Save and New look up value is showing empty .

  2. Indra says:

    How to retrieve the Primary Field Name value of an entity using JavaScript.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s