Set field values using parameters passed to a form (Developer Guide for Dynamics 365 Customer Engagement) (2024)

  • Article

The content in this topic can be used for Dynamics 365 for Customer Engagement. You can set default values for new records created by users by specifying attribute values in the URL that is used to open the form. By default, these values are set in the form, but can be changed by users before they save the record.

Pass parameters to set field record values

Note

You can pass parameter values to the form to set field values using the Xrm.Navigation.openForm function. For an example, see Example: Use Xrm.Navigation.openForm to Open a New Window.

When you open a new form by using the URL address, you can include arguments in the extraqs parameter to set field values. The following requirements must be met:

Example: Set the value for string fields

The following sample sets the value for the Name field of a new account record to "New Account".

The unencoded value for the extraqs parameter is “name=New Account”.

/main.aspx?etn=account&extraqs=name%3DNew%20Account&pagetype=entityrecord 

Set values for lookup fields

The following table describes five types of lookup fields. For examples using lookup fields, see Example: Set the Value for Lookup Fields and Example: Use Xrm.Navigation.openForm to Open a New Window.

Lookup TypeDescription
simple lookupAllows for a single reference to one type of entity.
customer lookupAllows for a single reference to either an account or a contact record.
owner lookupAllows for a single reference to either a team or a system user record.
partylist lookupAllows for multiple references to multiple entities.
regarding lookupAllows for a single reference to multiple entities.

The following guidelines apply when setting the value of a lookup on a form using a query string argument:

  • For simple lookups you must set the value and the text to display in the lookup. Use the suffix “name” with the name of the attribute to set the value for the text.

    Don’t use any other arguments.

  • For customer and owner lookups you must set the value and the name in the same way you set them for simple lookups. In addition you must use the suffix “type” to specify the type of entity. Allowable values are account, contact, systemuser, and team.

  • You can’t set the values for partylist or regarding lookups.

Example: Set the value for lookup fields

To set values for lookup fields, use the data value, the name value, and for customer or owner lookups only, specify the type value for the respective field. The following sample sets the owner field to a user named “Mark Folkerts”.

The unencoded value for the extraqs parameter is “ownerid={B8C6E040-656E-DF11-B414-00155DB1891A}&owneridname=Mark Folkerts&owneridtype=systemuser”.

/main.aspx?etn=lead&pagetype=entityrecord&extraqs=ownerid%3D%7bB8C6E040-656E-DF11-B414-00155DB1891A%7d%26owneridname%3DMark%20Folkerts%26owneridtype%3Dsystemuser 

The following sample sets the primary contact field to a user named “Yvonne McKay (sample)”.The unencoded value for the extraqs parameter is “primarycontactid={43b58571-eefa-e311-80c1-00155d2a68c4}&primarycontactidname=Yvonne McKay (sample)”.

/main.aspx?etn=account&pagetype=entityrecord&extraqs=primarycontactid%3D%7B43b58571-eefa-e311-80c1-00155d2a68c4%7D%26primarycontactidname%3DYvonne%20McKay%20(sample) 

Note

For a simple lookup like this, you don’t have to set a type value.

Example: Set the value for date fields

The following sample sets the Est. Close Date field for a new opportunity to January 31, 2011. The unencoded value for the extraqs parameter is “estimatedclosedate=01/31/11”.

/main.aspx?etn=opportunity&extraqs=estimatedclosedate%3D01%2F31%2F11&pagetype=entityrecord 

Example: Set the value for option set fields

To set the value for an Option set field, set the integer value for the option. The following sample sets the Role field value to “Decision Maker” in a new contact record.

The unencoded value for the extraqs parameter is “accountrolecode=1”.

/main.aspx?etn=contact&extraqs=accountrolecode%3D1&pagetype=entityrecord 

Example: Set the value for multi-select option set fields

To set the value for multi-select option set field, Specify integer values for the options in the URL that is used to open the form. For example, to set the options for the Hobbies field, the unencoded value for the extraqs parameter will be “hobbies=[1,3,4]”.

/main.aspx?etn=contact&extraqs=hobbies%3D%5B1%2C3%2C4%5D&pagetype=entityrecord 

Example: Use Xrm.Navigation.openForm to open a new window

The following sample sets default values on several different fields and shows how to use the Xrm.Navigation.openForm function. It is equivalent to the previous example that used the window.open method.

function OpenNewContact() { var parameters = {}; //Set the Parent Customer field value to “Contoso”. parameters["parentcustomerid"] = "2878282E-94D6-E111-9B1D-00155D9D700B"; parameters["parentcustomeridname"] = "Contoso"; parameters["parentcustomeridtype"] = "account"; //Set the Address Type to “Primary”. parameters["address1_addresstypecode"] = "3"; //Set text in the Description field. parameters["description"] = "Default values for this record were set programmatically."; //Set Do not allow E-mails to "Do Not Allow". parameters["donotemail"] = "1"; // Define the entity name to open the form var entityFormOptions = {}; entityFormOptions["entityName"] = "contact";// Open the form Xrm.Navigation.openForm(entityFormOptions, parameters).then( function (success) { console.log(success); }, function (error) { console.log(error); }); } 

Example: Use window.open to open a new window

The following sample sets default values on several different fields and shows how to use encodeURIComponent to encode the value of the extraqs parameter. If you use the window.open method, you can control the features of the window that is opened.

function OpenNewContact() { //Set the Parent Customer field value to “Contoso”. var extraqs = "parentcustomerid={F01F3F6D-896E-DF11-B414-00155DB1891A}"; extraqs += "&parentcustomeridname=Contoso"; extraqs += "&parentcustomeridtype=account"; //Set the Address Type to “Primary”. extraqs += "&address1_addresstypecode=3"; //Set text in the Description field. extraqs += "&description=Default values for this record were set programatically."; //Set Do not allow E-mails to "Do Not Allow". extraqs += "&donotemail=1"; //Set features for how the window will appear. var features = "location=no,menubar=no,status=no,toolbar=no"; // Open the window. window.open("/main.aspx?etn=contact&pagetype=entityrecord&extraqs=" + encodeURIComponent(extraqs), "_blank", features, false); } 

See also

Open Forms And Views with a URL
openForm
Configure a form to accept custom querystring parameters

Set field values using parameters passed to a form (Developer Guide for Dynamics 365 Customer Engagement) (2024)
Top Articles
Latest Posts
Article information

Author: Aracelis Kilback

Last Updated:

Views: 5740

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Aracelis Kilback

Birthday: 1994-11-22

Address: Apt. 895 30151 Green Plain, Lake Mariela, RI 98141

Phone: +5992291857476

Job: Legal Officer

Hobby: LARPing, role-playing games, Slacklining, Reading, Inline skating, Brazilian jiu-jitsu, Dance

Introduction: My name is Aracelis Kilback, I am a nice, gentle, agreeable, joyous, attractive, combative, gifted person who loves writing and wants to share my knowledge and understanding with you.