This documentation is archived and is not being maintained.

Create Activity Record Templates

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Create buttons that will open new activity forms that are populated with default data. By default, most entities support including values in the query string that will set default values for a new form opened by using the URL address. However, activity entities currently do not support this technique. This example demonstrates a workaround.

The URL defined for a button in ISV.Config may contain additional query string parameters that can be read from the DHTML object to start specific conditional logic in the form onload event to set default values.

This sample creates three buttons on the ccount form. Each button will open a new Task form that contains different default data. There are three buttons: Low, Normal, and High to correspond to the priority of the task. Logic in the OnLoad event for the Task form will set default data for four fields as shown in the following table.

Button LabelPrioritySubjectDueRegarding
LowLowLow Priority:3 days from todayThe Account record from which the Task was created
NormalNormalNormal Priority:2 days from today 
HighHighHigh Priority:1 day from today 

Completing this task involves two steps:

  1. Configure the Buttons using ISV.Config.
  2. Configure a script in the OnLoad event for the Task form.

Example ISV.Config

The ISV.Config must be modified to create the buttons in the toolbar for the Account entity. The toolbar must only appear for Accounts that have been saved. The URL attribute of the button elements uses the URL to the Task activity form and includes some additional query string values.

See also:

Account Toolbar element from ISV.Config:

<!-- The Account Tool Bar -->
<ToolBar ValidForCreate="0"  ValidForUpdate="1">
 <Button Icon="/_imgs/ico_18_4212.gif" Url="/activities/task/edit.aspx?prioritycode=0&amp;subject=Low Priority:">
   <Title LCID="1033" Text="Low" />
   <ToolTip LCID="1033" Text="Low Priority Task" />
 <Button Icon="/_imgs/ico_18_4212.gif" Url="/activities/task/edit.aspx?prioritycode=1&amp;subject=Normal Priority:">
   <Title LCID="1033" Text="Normal" />
   <ToolTip LCID="1033" Text="Normal Priority Task" />
 <Button Icon="/_imgs/ico_18_4212.gif" Url="/activities/task/edit.aspx?prioritycode=2&amp;subject=High Priority:">
   <Title LCID="1033" Text="High" />
   <ToolTip LCID="1033" Text="High Priority Task" />

Toolbar Configuration

Note the following with regard to how the button elements in the toolbar have been configured:

  • The ampersand symbol "&" used to separate query string values must be escaped using "&amp;" within the XML used in ISV.Config.
  • All query string values must correspond to attribute names for the entity. Arbitrary query string values are not supported.
  • The PassParameters attribute is not used. Use of this attribute to pass values related to the Account record will conflict with the parameters that are passed in the URL to set values in the Task record.

Example Task OnLoad Event Code

The Task OnLoad event code reads the information passed from the querystrings through the object. Based on the values that are passed, specific default values are set in the new Task form. The user may alter these default values before the Task is saved.

Task OnLoad Event Code


// Only for new Tasks created with querystring parameters added.
if ((crmForm.FormType == CRM_FORM_TYPE_CREATE) && (
// Create an array to store the querystring parameters.
 var request= new Array(); 
 for (var i in vals) 
  vals[i] = vals[i].replace(/\+/g, " ").split("="); 
  request[unescape(vals[i][0])] = unescape(vals[i][1]); 
 // Get the priority and subject fields from the querystring.
 var prioritycode = parseInt(request["prioritycode"],10);
 var subject = request["subject"];
 // Set the due date based on the priority.
 var oToday = new Date();
 var oDate = oToday;
 var iDate = oToday.getDate();
 switch (prioritycode)
  case 0: //Low Priority
  iDate = iDate+3
  case 1: //Normal Priority
  iDate = iDate+2
  case 2: //High Priority
  iDate = iDate+1
 // Set the values for the priority, subject, and due date.
 crmForm.all.prioritycode.DataValue = prioritycode;
 crmForm.all.subject.DataValue = subject;
 crmForm.all.scheduledend.DataValue = oDate;
 // Get information from the parent account.
 if (window.opener)
  var oParentCrmForm = window.opener.document.all.crmForm;
  if (oParentCrmForm)
    var gRecordId = oParentCrmForm.ObjectId;
    var sRecordName =;
    var sFormTypeName = oParentCrmForm.ObjectTypeName;
    var lookupData = new Array();
    var lookupItem = new Object(); = gRecordId;
    lookupItem.typename = sFormTypeName; = sRecordName;
    lookupData[0] = lookupItem;
    // Set the value of the Resgarding lookup field
    crmForm.all.regardingobjectid.DataValue = lookupData;

Task OnLoad Event Code Logic

Note the following logic applied in the Task OnLoad event code:

  • The crmForm.FormType property value is used as a condition so that the logic is only applied before a new record is created.
  • The DHTML object must exist for the code to run.
  • This sample uses logic to parse the object and make the values available in an array called 'request' that resembles the way query string values are made available in ASP.NET server-side code. This particular technique is not required, but the object represents a string with name/value pairs separated by the ampersand symbol that must be parsed before it can be used.
  • For other entities, setting the value of an appropriately named query string parameter is enough to set the value for text fields. For example, setting the name value for a new account can be done by using this URL attribute for a button element in the ISV.Config:

    However, the Task entity form does not behave the same way. Although the value for the subject text field is available in the object, it must be explicitly set.

  • The prioritycode value that is passed must be converted to an integer value by using the parseInt function.
  • To set the Due field, a DateTime value must be set. In this case, the date portion is adjusted based on the priority.
  • Information about the parent record is usually passed from a button using the PassParameters attribute. However, this method is incompatible with manually setting query string values. Instead of passing information about the account using the querystring, information about the originating account record is obtained using window.opener. This information is used to set the Regarding lookup field value.

© 2010 Microsoft Corporation. All rights reserved.