locked
Getting look up value text into single line of text MSCRM 2011 RRS feed

  • Question

  • Hi,

    How will I get lookup value name into single line of text in mscrm 2011.

    ex:

    Entity name : Contact

    In this I had a lookup field Country = INDIA

    and Text field Country Name

    I need to display selection upon country lookup value name auto fill into the text field as INDIA.


    Thanks, Toushu

    Thursday, November 29, 2012 11:20 AM

Answers

All replies

  • Please check the following link and implement your business logic
    http://garethtuckercrm.com/2011/03/16/jscript-reference-for-microsoft-dynamics-crm-2011/

    write code on change of your lookup field

    // JScript source code
    function setTheValueOfCountry() {
    
        //Get a lookup value 
        var lookupItem = new Array();
        lookupItem = Xrm.Page.getAttribute("schemaNameOfCountryLookupField").getValue();
    
        if (lookupItem != null) {
    
            var name = lookupItem[0].name;
            var guid = lookupItem[0].id;
            var entType = lookupItem[0].entityType;
            var Country = Xrm.Page.data.entity.attributes.get("schemaNameOfCountryTextField");
            Country.setValue(name);
        }
    
       
    
    }

    If you need more information please let me know



    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!




    • Edited by MubasherSharif Thursday, November 29, 2012 11:32 AM
    • Proposed as answer by _Vikram Thursday, November 29, 2012 11:36 AM
    • Marked as answer by Rahul-22 Thursday, November 29, 2012 11:56 AM
    Thursday, November 29, 2012 11:26 AM
  • Hi,

    Just addition to Mubasher Sharif's response. please put the condition to check the null value for lookup field.

    function setTheValueOfCountry() {
        if (Xrm.Page.data.entity.attributes.get("schemaNameOfCountryLookupField").getValue() != null) {
            var countryLookup = Xrm.Page.data.entity.attributes.get("schemaNameOfCountryLookupField").getValue()[0].name;
            var Country = Xrm.Page.data.entity.attributes.get("schemaNameOfCountryTextField");
            Country.setValue(countryLookup);
        }
        else {
            var Country = Xrm.Page.data.entity.attributes.get("schemaNameOfCountryTextField");
            Country.setValue("");
        }

    }


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful !!!
    Vikram !

    Thursday, November 29, 2012 11:36 AM
  • Hi Rahul,

    On Change of the look-up Field you can execute Below script. ( addition to Mubasher Sharif's response)

    // JScript source code
    function setTheValueOfCountry() {

     var lookupItem = new Array();
        lookupItem = Xrm.Page.getAttribute("new_countryid").getValue(); // country lookup schema

        if (lookupItem != null) {
            var name = lookupItem[0].name;
            var Country = Xrm.Page.data.entity.attributes.get("new_country"); // country text field schema
            Country.setValue(name);

    // to Hide/show the section based on country . For example i considered 3 countries

        switch (name) {
                case "India":
                        HideShowSection(2, 1, true)
       HideShowSection(2, 2, false)
       HideShowSection(tabNo, 3, false)
                    break;
                case "USA":
                        HideShowSection(2, 1, false)
       HideShowSection(2, 2, true)
       HideShowSection(2, 3, false)
                    break;

      case "UK":
                        HideShowSection(2, 1, false)
       HideShowSection(2, 2, false)
       HideShowSection(2, 3, true)
                    break;
       }
          }
    }


    function HideShowSection(tabnumber, section, visible) {
        Xrm.Page.ui.tabs.get(tabnumber).sections.get(section).setVisible(visible);
    }


    Chandan

    Thursday, November 29, 2012 11:52 AM
  • Thanks a lot Sharif..

    Its working fine..


    Thanks, Toushu

    Thursday, November 29, 2012 11:56 AM