jump to navigation

Setting a default value on a lookup field in Microsoft Dynamics CRM 2011 May 23, 2011

Posted by jarrettexpertcrm in Microsoft CRM General.
Tags: , , , , , , , , , , , , , , ,
7 comments


In previous a post i posted how to default a value on a lookup field in 4.0. Here is the solution for CRM 2011
function priceList()
{
//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = ‘{27457CD-3C7C-E011-8E52-1CC1DE7983EB%257d}’;
lookupItem.typename = ‘pricelevel’;
lookupItem.name = ‘test’;
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
Xrm.Page.getAttribute(“pricelevelid”).setValue(lookupData);
}

In my example i am getting the pricelist “test” and defaulting it in the pricelist field on the Opportunity entity. Below is the template you can use to utilize the code for a different look up and values.
function priceList()
{
//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = ‘{Fields Guid}’;
lookupItem.typename = ‘Entity Name’;
lookupItem.name = Lookup Value;
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
Xrm.Page.getAttribute(“FieldName”).setValue(lookupData);

}

Enjoy!!

For more information about Dynamics Four you can contact us at http://www.dynamics4.com

Microsoft Dynamics CRM 4.0 Primary Contact Filter July 14, 2010

Posted by jarrettexpertcrm in Microsoft CRM General.
Tags: , , , , , , , , , ,
add a comment

I have received quite a few requests to have primary contact on accounts, when clicked, only show the contacts for that particular account. For those that may already have some sort of look up filter in place they may have experienced this problem, and for those that don’t, well here is a solution that will work. When in an account with a “&” in the name, you click primary contact and you receive an error. Here is a fix for that.

Account Onload:

if (crmForm.FormType == 2 && crmForm.ObjectId != null)
{
var name = crmForm.all.name.DataValue;
crmForm.all.primarycontactid.additionalparams =  ‘search=’ + name.replace(“&”,”%26″).replace(“+”,”%2b”);
}
Hope this helps!
For more information about Dynamics Four or to contact us please visit http://www.dynamics4.com