Assigning deafult value to lookup field RRS feed

  • Question

  • Hi i need to assign default value to a lookup field using jScript


    any suggestion ???


    thanks in advance

    Tuesday, September 21, 2010 10:31 AM


All replies

  • you should be able to set it through below sample code from sdk

    //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 = '{1AAC1363-01A1-DB11-8432-0003FF9CE217}';
      lookupItem.typename = 'account';
      lookupItem.name = 'A Bike Store';
    // Add the object to the array.
      lookupData[0] = lookupItem;
    // Set the value of the lookup field to the value of the array.
      crmForm.all.parentaccountid.DataValue = lookupData;

    Mahain : http://mahenderpal.wordpress.com
    Tuesday, September 21, 2010 10:34 AM
  • Tuesday, September 21, 2010 10:36 AM
  • var lookupItem = new Array;
    lookupItem = crmForm.all..DataValue;
    // If there is data in the field, show it in a series of alerts.
    if (lookupItem[0] != null){
    // The text value of the lookup
    alert("Display Value"+lookupItem[0].name);
    // The GUID of the lookup
    // The entity type name. by using the entityname get the ObjectTypeCode from
    //the MetadataSchema.Entity table
    alert("Entity Name"+lookupItem[0].typename);

    by using the entity name get the "ObjectTypeCode" from the "MetadataSchema.Entity" table from DB
    now its ready to call the function.
    call it onLoad of the form and it need to be done on creation of new record.

    //the following will take 4 parameters
    //1st GUID of the record to be set as default
    function setDefault4Lookup(guid,entityName,displayValue,attributeID)
    var lookupItem = new Array();
    // Values on the signature of LookupControlItem are: GUID, type code and finally the name of the
    //lookup value
    lookupItem[0] = new LookupControlItem (guid, entityName, displayValue);
    //Set the form control value to the lookupItem just created
    attributeID.DataValue = lookupItem;


    click here http://bproud2banindian.blogspot.com/2009/12/default-value-for-lookups.html

    Tuesday, September 21, 2010 1:45 PM