Export (0) Print
Expand All

How to Use Window.opener

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

When Microsoft Dynamics CRM forms are opened in relation to another record you can access the other record by using the window.opener method. This is also true if the page is opened by using a button configured in isv.config for the taskbar of the parent record.

Example

The following code example shows how to access the values of an account from a task. The code is in the task's onLoad event.

The result is that the task has an improved default subject value that includes the account name. The action must only occur when the task is created.

// This only applies to a new task.
if (crmForm.FormType == 1)
{
 // Check to confirm that the window.opener is present.
 if (window.opener)
 {
  // Get the values of the parent form.
  var oParentCrmForm = window.opener.document.all.crmForm;
    
  // Check that you obtained the values of the parent form and
  // that the parent form is an account.
  if (oParentCrmForm && oParentCrmForm.ObjectTypeCode == 1)
  {
   // Get the name of the account.
   var sAccountName = oParentCrmForm.all.name.DataValue;
        
   // Set the default value of the task subject to
   // include a reference to the related account.
   crmForm.all.subject.DataValue = "Account: " + sAccountName;
  }
 }
}

Example

The following code example shows how to set the values of an account from a task. The code is in the task's onSave event.

The result is that the account description field is updated to include a reference to data from the task.

// Check to confirm that the window.opener is present.
if (window.opener)
{
 // Get the value of the owner of the task.
 var oOwner = crmForm.all.ownerid.DataValue;
 var oTaskDesc = crmForm.all.description.DataValue;
    
 // Confirm that there is data in the owner field.
 if (oOwner != null)
 {
    
  // Get the parent form.
  var oParentCrmForm = window.opener.document.all.crmForm;
  // Set the message.
  var msg = "New task assigned to "+oOwner[0].name;
  msg += "  notes: "+oTaskDesc;
  // Set the value to the parent form.
    
  // Confirm that the description field is there.
  if (oParentCrmForm.all.description)
   {
   // Add the message to the description field.
   if (oParentCrmForm.all.description.DataValue != null)
   {
    oParentCrmForm.all.description.DataValue += msg;
   }
   else
   {
    oParentCrmForm.all.description.DataValue = msg;
   }
  }
 }
}

© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2015 Microsoft