jump to navigation

Setting a default value on a lookup field in Microsoft Dynamics CRM 4.0 October 27, 2009

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

d4 logo I got a request to set the “Unit” on an Opportunity Product to always default to “Primary unit” when a product is created. Setting default values on lookup fields seems to be a common request, so i decided to post the code to achieve this. This is an Onload Event.

//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 = ‘{299F37C4-6D9D-4628-ADF9-9479A6F209BA}’;
   lookupItem.typename = ‘uom’;
   lookupItem.name = ‘Primary Unit’;
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.uomid.DataValue = lookupData;

If you want to use this code for other lookups, here is what you need to change:

//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.
   crmForm.all.FieldName.DataValue = lookupData;

Enjoy!!

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

Hiding multiple tabs based on picklist value in Microsoft CRM 4.0 October 5, 2009

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

d4 logoBeing able to hide tabs until a certain value is selected in a picklist is becoming a common request. So i decided to post how you can accomplish that. Apply this code on the onload and onchane events (replace with your field names).

if
(crmForm.all.new_fieldname.DataValue == 1)
{
crmForm.all.tab1Tab.style.display = ‘none’;
crmForm.all.tab2Tab.style.display = ‘none’;
crmForm.all.tab3Tab.style.display = ‘inline’;
crmForm.all.tab4Tab.style.display = ‘inline’;
crmForm.all.tab5Tab.style.display = ‘none’;
crmForm.all.tab6Tab.style.display = ‘none’;
crmForm.all.tab7Tab.style.display = ‘none’

}

else if
(crmForm.all.new_fieldname.DataValue == 2)
{
crmForm.all.tab1Tab.style.display = ‘none’;
crmForm.all.tab2Tab.style.display = ‘none’;
crmForm.all.tab3Tab.style.display = ‘inline’;
crmForm.all.tab4Tab.style.display = ‘none’;
crmForm.all.tab5Tab.style.display = ‘inline’;
crmForm.all.tab6Tab.style.display = ‘none’;
crmForm.all.tab7Tab.style.display = ‘none’

}
else if
(crmForm.all.new_fieldname.DataValue == 3)
{
crmForm.all.tab1Tab.style.display = ‘none’;
crmForm.all.tab2Tab.style.display = ‘none’;
crmForm.all.tab3Tab.style.display = ‘inline’;
crmForm.all.tab4Tab.style.display = ‘none’;
crmForm.all.tab5Tab.style.display = ‘none’;
crmForm.all.tab6Tab.style.display = ‘inline’;
crmForm.all.tab7Tab.style.display = ‘none’

}
else if
(crmForm.all.new_fieldname.DataValue == 4)
{
crmForm.all.tab1Tab.style.display = ‘none’;
crmForm.all.tab2Tab.style.display = ‘none’;
crmForm.all.tab3Tab.style.display = ‘inline’;
crmForm.all.tab4Tab.style.display = ‘none’;
crmForm.all.tab5Tab.style.display = ‘none’;
crmForm.all.tab6Tab.style.display = ‘inline’;
crmForm.all.tab7Tab.style.display = ‘none’
}

For more information about Dynamics Four or to contact us please visit http://www.dynamics4.com