Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

lookup field

(1) ShareShare
ReportReport
Posted on by 12,081 Moderator

Hi all,

I have lookup field as shown below

Enum-Values-for-voucher-entity.png 85064.Untitled1.png

Phase pipeline is my entity. I have to default Phase pipeline field. I write below code for achieving this defaulting but it is not working. 

function paymentMethodRequired_onchange() {

var lookup = new Array();
lookup[0] = new Object();
lookup[0].value = "10";
Xrm.Page.getAttribute("aw_pipelinephase").setValue(lookup);

}

It is giving me undefined value instead of 10 as shown below

7802.Untitled2.png

This lookup contain these values

0068.Untitled3.png

What can I do to achieve this task?

Thank you

*This post is locked for comments

  • Verified answer
    TNS Profile Picture
    TNS 1,195 on at
    RE: lookup field

    Hi,

      change your code:

       lookup[0].aw_value = '10';// I assume id is my primary field

      lookup[0].aw_description = 'Auto process';//I assume name is my description field

        lookup[0].entityType = 'aw_pipelinephase';//I assume entity type is my custom entity             name

      "lookup[0].aw_value" change this with  "lookup[0].id" and then  lookup[0].id= give the record id here ...

     "lookup[0].aw_description"  change this with "lookup[0].name" and as I think you want to enter the vakue 10 show you can write  lookup[0].name="10";

  • Verified answer
    PS Profile Picture
    PS 23,577 on at
  • Abdul Wahab Profile Picture
    Abdul Wahab 12,081 Moderator on at
    RE: lookup field

    Hi Prashant Shukla

    I use this approach on triggers. I only need to know How can I set lookup values through code

    Thank you

  • Suggested answer
    Kishor Kumar Profile Picture
    Kishor Kumar 3,702 on at
    RE: lookup field

    Hi Abdul Wahab,

    Just check this below link,

    jarrettexpertcrm.wordpress.com/.../setting-a-default-value-on-a-lookup-field-in-microsoft-dynamics-crm-2011

    Please let me know if you are able to achieve this way, or  as Prashant  suggested you could use the workflow to make much better!!  

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
    RE: lookup field

    Hi Abdul

    A workflow would be much easier for this.

    Create a workflow like below screenshot:

    2021.1.PNG

    Under update, click set properties and set '10' in your lookup field

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
    RE: lookup field

    your primary field should be name

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,081 Moderator on at
    RE: lookup field

    Hi Kishor Kumar U

    I use the below code

    function paymentMethodRequired_onchange() {

    debugger;

    var require = Xrm.Page.getAttribute('aw_isqualified').getValue();

    var lookup = new Array();

    lookup[0] = new Object();

    lookup[0].aw_value = '10';// I assume id is my primary field

    lookup[0].aw_description = 'Auto process';//I assume name is my description field

    lookup[0].entityType = 'aw_pipelinephase';//I assume entity type is my custom entity name

    Xrm.Page.getAttribute("aw_pipelinephase").setValue(lookup);

    0184.Untitled8.png

    It also showing me undefined

    0184.Untitled8.png

    Where I wrong please suggest me?

    Thank you

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
  • Verified answer
    Kishor Kumar Profile Picture
    Kishor Kumar 3,702 on at
    RE: lookup field

    Hi Abdul Wahab,

    Try this,

    function paymentMethodRequired_onchange() {

    var lookup = new Array();

    lookup[0] = new Object();

    lookup[0].id = recorid;

    lookup[0].name = recordname;

    lookup[0].entityType = entityname;

    Xrm.Page.getAttribute("attributename").setValue(lookup);

    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans