Duane Napier's Blog

Microsoft Dynamics CRM

Getting values from form fields in JavaScript – CRM 2011

Posted by duanenapier on April 12, 2011

This post will focus on the new Xrm schema and cover getting the values for text fields, picklist fields and lookup fields in CRM 2011.Refer to the Web Resources post for specifics how to create and use JavaScript files.

Get the value from a Lookup Field:

//1st Thing – You need to create an Array variable
var UserlookupItem = new Array;
var OpportunitylookupItem = new Array;

//2nd Thing – You need to get the Value. The getValue function will return the respective object’s return type. In this case it will return an Array because the Coverage Member I have created is a lookup to the user table.
UserlookupItem = Xrm.Page.getAttribute(“new_coveragemember”).getValue();
OpportunitylookupItem= Xrm.Page.getAttribute(“new_opportunity”).getValue();

//3rd Thing – Get the first item in the array, which is the name.
var MyNewName;
MyNewName = UserlookupItem[0].name;
MyNewName += ‘-’ + OpportunitylookupItem[0].name;
alert(MyNewName);

Get the value from a Picklist Field:
//You may want the ordinal value or the text value so we will grab both
//1st Thing – Get the ordinal, or integer value using getValue()
var intListItem = Xrm.Page.data.entity.attributes.get(“CompanyType”).getValue();

//2nd  Thing – Get the text value using getText()
var txtListItem = Xrm.Page.data.entity.attributes.get(“CompanyType”).getText();

Get the value from a Text Field:
//1st Thing – 1 simple function call of getValue() can grab the value
var WebSite = Xrm.Page.data.entity.attributes.get(“WebAddress”).getValue();
alert(WebSite);

About these ads

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 )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: