web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to set 'Unit' on Quote product to a default value CRM 2011

(0) ShareShare
ReportReport
Posted on by 190

I am trying to default the field Unit to the Lookup value of 'KG' on Quote Products. I have tried the following 2 methods and neither seem to work. Could someone please advise.

Method 1:

function SetDefaultUnit() {
//Create an array to set as the DataValue for the lookup control.
var lookupData1 = new Array();
//Create an Object add to the array.
var lookupItem1= new Object();
//Set the id, typename, and name properties to the object.
lookupItem1.id = '{DD0CD04E-6D92-E311-86C4-00505688378E}';
lookupItem1.typename = 'uom';
lookupItem1.name = 'KG';
// Add the object to the array.
lookupData1[0] = lookupItem1;
// Set the value of the lookup field to the value of the array.
crmForm.all.defaultuomid.DataValue = lookupData1
}

Method 2:

if (Xrm.Page.getAttribute("uomid").getValue() == null)
{
var lookupData = new Array();
var lookupItem= new Object();
lookupItem.id = '{DD0CD04E-6D92-E311-86C4-00505688378E}';
lookupItem.entityType = 'uom';
lookupItem.name = 'KG';
// 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("uomid").setValue() =lookupData;
Xrm.Page.getAttribute("uomid").setSubmitMode("always");
alert(lookupData);
}2063.Capture.PNG

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Shane Brown Profile Picture
    190 on at
    RE: How to set 'Unit' on Quote product to a default value CRM 2011

    Thanks i got it working using the following code:

    function SetDefaultUnit() {
    if (Xrm.Page.getAttribute("uomid").getValue() == null)
    {
    var lookupData = new Array();
    lookupData[0]= new Object();
    lookupData[0].id = '{DD0CD04E-6D92-E311-86C4-00505688378E}';
    lookupData[0].entityType = 'uom';
    lookupData[0].name = 'KG';
    // Set the value of the lookup field to the value of the array.
    Xrm.Page.getAttribute("uomid").setValue(lookupData);
    Xrm.Page.getAttribute("uomid").setSubmitMode("always");
    }
    }

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: How to set 'Unit' on Quote product to a default value CRM 2011

    Use this code:

    if (Xrm.Page.getAttribute("uomid").getValue() == null)

    {

    var lookupData = new Array();

    lookupData[0]= new Object();

    lookupData.id = '{DD0CD04E-6D92-E311-86C4-00505688378E}';

    lookupData.entityType = 'uom';

    lookupData.name = 'KG';

    // Set the value of the lookup field to the value of the array.

    Xrm.Page.getAttribute("uomid").setValue(lookupData);

    Xrm.Page.getAttribute("uomid").setSubmitMode("always");

    alert(lookupData);

    }

  • Suggested answer
    prt33k Profile Picture
    6,907 on at
    RE: How to set 'Unit' on Quote product to a default value CRM 2011

    since it is crm 4.0, Xrm wont work.

    In method I, can you please try removing curly braces i.e. lookupItem.id = 'DD0CD04E-6D92-E311-86C4-00505688378E'

    or even try using:

    crmForm.all.defaultuomid.DataValue = [{id: 'DD0CD04E-6D92-E311-86C4-00505688378E', name: 'KG', typename: 'uom'}]

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans