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)

Binding a Lookup to an Entity in javascript

(0) ShareShare
ReportReport
Posted on by 165

Hello Friends,

Please, I currently want to bind a lookup field to won opportunities using javascript. I want the text to be the display field while the value will be the id (to be submitted to the database) .Code snippet will be greatly appreciated.

Thanks

*This post is locked for comments

I have the same question (0)
  • Frank Ewans Profile Picture
    165 on at
    RE: Binding a Lookup to an Entity in javascript

    Will try that out.

  • Frank Ewans Profile Picture
    165 on at
    RE: Binding a Lookup to an Entity in javascript

    Thanks Adam. Will get back to you after I test this.

  • Suggested answer
    Aileen Gusni Profile Picture
    44,524 on at
    RE: Binding a Lookup to an Entity in javascript

    Hi Franks,

    Adam is correct, you can follow his way, he is correct you don't need any javascript for this.

    And yes, I have tried this, I try to create a new child record under the Won Opportunity lookup.

    So, it worked.

    1. You just create a lookup field to Opportunity

    2. Go to Form Editor and you edit the field property detail

    3. Change the lookup filter default view to Won Opportunities

    4. And you can turn off the view selector to prevent user change another Opportunity view, and of course save it publish it.

    5. When you in the Project entity record, when you click the Lookup to Won Opportunity, it will filter the Project to only choose and linked (Append) to Won Opportunity record.

    Hope this helps!

    Thanks.

  • Community Member Profile Picture
    on at
    RE: Binding a Lookup to an Entity in javascript

    You don't need javascript, you can modify a lookup control on the form to use a different view than the normal lookup view. Select Won Opportunities and you should be OK. I have not tested this. It might fail if it tries to prevent you appending a new Project record to the closed Opp, but I think you will be OK.

  • Frank Ewans Profile Picture
    165 on at
    RE: Binding a Lookup to an Entity in javascript

    Hi Chitrarasan Duraisamy, Thanks for the code snippet. Please can you make the code more generic (specific to an MS CRM entity. won opportunities in particular).

    Thanks

  • Frank Ewans Profile Picture
    165 on at
    RE: Binding a Lookup to an Entity in javascript

    Thanks for your response. Am trying to lookup all won opportunities in my project page so i can commence a new project on them.

    Thanks

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: Binding a Lookup to an Entity in javascript

    Hi Frank,

    What do you mean? Can help to explain more?

    "I currently want to bind a lookup field to won opportunities using javascript."

    Because the fundamental thing here is you cannot update the Won Opportunity, it has already closed and inactive, read only. Unless it is still open or you re-open it.

    Thanks.

  • Royal King Profile Picture
    27,686 on at
    RE: Binding a Lookup to an Entity in javascript

    either one of the below code will set lookup value for an attribute.

    //Set a lookup value

       var value = new Array();

       value[0] = new Object();

       value[0].id = idValue;

       value[0].name = textValue;

       value[0].entityType = typeValue;

       Xrm.Page.getAttribute("yourAttributeSchemaName").setValue(value);

    //setlookup in one line

    Xrm.Page.getAttribute("fieldName").setValue( [{id: idValue, name: textValue, entityType: typeValue}]);

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans