Answered by:
Set a Default Value for a Lookup?

Question
-
Hi All,
I have a requirement in crm 2011 where i have to set default value for Unit Group and Default Unit in Product Entity.I have wriiten a javascript for the same but it does not seem to work!!!!
function setdefaultvalue()
{
//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 = '{142d4322-1268-4560-ae20-1c1250f4bed8}';
lookupItem.typename = 'uomschedule';
lookupItem.name = 'Default 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.defaultuomscheduleid.DataValue.0= lookupData[0];
}function setdefaultvalue1()
{
//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 = '{0e5db133-a5f2-4c69-b8a5-4585d45c92f0}';
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.defaultuomid.DataValue.0 = lookupData[0];
}Please let me know what is going wrong in this?
- Moved by Xiaopeng Wu Tuesday, March 8, 2011 9:58 PM Forum consolidation (From:CRM Online)
Friday, December 10, 2010 5:28 AM
Answers
-
So you have sorted it then?
Technically you are still using an array and an object but it is using the JavaScript shortcut syntax.
MSCRM Bing'd - http://bingsoft.wordpress.com Check out the CRM 4 to CRM 2011 JavaScript Converter Tool CRM Forum Guidance on how to Help Us Help You - Marked as answer by Bilal Sayed Saturday, December 11, 2010 8:47 AM
Friday, December 10, 2010 2:16 PMModerator -
Hey,
Instead of taking an array we can do it like this:
crmForm.all.defaultuomscheduleid.DataValue = [{id: '142d4322-1268-4560-ae20-1c1250f4bed8', name: 'Default Unit', typename: 'uomschedule'}];
crmForm.all.defaultuomid.DataValue = [{id: '0e5db133-a5f2-4c69-b8a5-4585d45c92f0', name: 'Primary Unit', typename: 'uom'}];
- Marked as answer by Bilal Sayed Saturday, December 11, 2010 8:47 AM
Friday, December 10, 2010 6:14 AM
All replies
-
Hey,
Instead of taking an array we can do it like this:
crmForm.all.defaultuomscheduleid.DataValue = [{id: '142d4322-1268-4560-ae20-1c1250f4bed8', name: 'Default Unit', typename: 'uomschedule'}];
crmForm.all.defaultuomid.DataValue = [{id: '0e5db133-a5f2-4c69-b8a5-4585d45c92f0', name: 'Primary Unit', typename: 'uom'}];
- Marked as answer by Bilal Sayed Saturday, December 11, 2010 8:47 AM
Friday, December 10, 2010 6:14 AM -
So you have sorted it then?
Technically you are still using an array and an object but it is using the JavaScript shortcut syntax.
MSCRM Bing'd - http://bingsoft.wordpress.com Check out the CRM 4 to CRM 2011 JavaScript Converter Tool CRM Forum Guidance on how to Help Us Help You - Marked as answer by Bilal Sayed Saturday, December 11, 2010 8:47 AM
Friday, December 10, 2010 2:16 PMModerator