Dynamics CRM Javascript · Javascript

Dynamics CRM 365 set Lookup & Regarding field while using Xrm.Navigation.openForm formParameters

Today we had a requirement to open new form on click of button and also set lookup field on the child entity form.

On MSDN docs sample code has provided the syntax for other data types but it does not have syntax for lookup field so I though of doing it on my trial instance.

Code to set lookup filed while using using Xrm.Navigation.openForm

var entityOptions = {};
entityOptions[“entityName”] = “account”;
entityOptions[“useQuickCreateForm”] = true;

var formParameters = {};
formParameters[“primarycontactid”] = “{35a17064-1ae7-e611-80f4-e0071b661f02}”;
formParameters[“primarycontactidname”] = “Test Contact”;

Xrm.Navigation.openForm(entityOptions, formParameters).then(
function (lookup) { console.log(“Success”); },
function (error) { console.log(“Error”); }

To set regarding field which is consist of multiple entities, below code can be used in formparameters.

function TaskLaunch(executionContext)

var formContext = executionContext.getFormContext();

var formParameters = {};

//Pass the regarding value
var regardingObjectId = formContext.data.entity.getId();
var projectName = formContext.getAttribute(“new_name”).getValue();

formParameters[“subject”]=”Record Deactivated”;

// Define the entity name to open the form
var entityFormOptions = {};
entityFormOptions[“entityName”] = “task”;
entityFormOptions[“useQuickCreateForm”] = true;

// Open the form
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
function (error) {

Hope this helps!

5 thoughts on “Dynamics CRM 365 set Lookup & Regarding field while using Xrm.Navigation.openForm formParameters

  1. This article was extremely helpful and was the reason I was able to add a task button to the contact entity!

    I’m just having trouble automatically filling the regarding field in the Quick Create: Task form that pops up after clicking the button. The name of the right contact shows up, but I receive an error code.

    I believe it’s because I’m not currently passing the “regardingobjecttypecode” within the formParameters. Would what I need to put here if the regarding record is a Contact?



Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s