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

Notifications

Announcements

No record found.

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)
  • Royal King Profile Picture
    27,686 on at

    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}]);

  • Aileen Gusni Profile Picture
    44,524 on at

    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.

  • Frank Ewans Profile Picture
    165 on at

    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

  • Frank Ewans Profile Picture
    165 on at

    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

  • Community Member Profile Picture
    on at

    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.

  • Suggested answer
    Aileen Gusni Profile Picture
    44,524 on at

    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.

  • Frank Ewans Profile Picture
    165 on at

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

  • Frank Ewans Profile Picture
    165 on at

    Will try that out.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans