This documentation is archived and is not being maintained.

Referencing Form Data

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

This example shows how to access data in a Microsoft Dynamics CRM form. The following sample reads data from several different types of fields in the default account form and displays them in a message for the user. This script can be tested by adding it to the OnSave event of the Account form.

var accountName;
var parentAccountName;
var relationshipType;

// Get the account name form a text field.
accountName =;

// Get the parent account name from a lookup field.
var ar = new Array();
if (crmForm.all.parentaccountid.DataValue != null)
 ar = crmForm.all.parentaccountid.DataValue;
 parentAccountName = ar[0].name;
 parentAccountName = "No Parent Account"; 

// Get the relationship type from a picklist field.
var text = crmForm.all.customertypecode.SelectedText;
if (text.length == 0)
 relationshipType = "No relationship type set";
 relationshipType = text;
// Display the message.
message = "This account is named "+accountName+". ";
message +="It is the child of "+ parentAccountName;
message +=", and the relationship is "+relationshipType;

© 2010 Microsoft Corporation. All rights reserved.