Getting values from form fields in JavaScript – CRM 2013
Posted by duanenapier on April 25, 2014
There are some subtle differences in CRM 2011 JavaScript vs. CRM 2013 JavaScript so this post will focus on the new Xrm schema and cover getting the values for text fields, picklist fields and lookup fields in Microsoft Dynamics CRM 2013. 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;
//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();
//3rd Thing – Get the first item in the array, which is the name.
var MyNewName;
MyNewName = UserlookupItem[0].name;
Get the value from a OptionSet (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 of the selected option using getValue()
var intListItem = Xrm.Page.getAttribute(“CompanyType”).getValue();
//2nd Thing – Get the text value of the selected option using getText()
var txtListItem = Xrm.Page.getAttribute(“CompanyType”).getText();
Get the value from a Text Field:
//1st Thing – 1 simple function call of getValue() can grab the value
var RecordName = Xrm.Page.getAttribute(“new_name”).getValue();
This entry was posted on April 25, 2014 at 10:22 am and is filed under JavaScript, Microsoft Dynamics CRM 2013. Tagged: CRM 2013, getAttribute, getText, getValue, JavaScript, lookup field, Microsoft Dynamics 2013, Optionset field. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a comment