locked
How to Retrieve lookup fields value to a single line text field in ms crm 2011 using javascript. RRS feed

  • Question

  • Hi,

    I have one req to retrieve a lookuop fiels data to a single line text field. using javascript in ms crm 2011 . That is I have TWo entities (Student and Parents) In Student Form have one lookup field for Guardain Name but  in Parents form I have one textfield for guardian name

    Here in parents form i will select reg number (reg no is a lookup with Student) then guardains name should be populated inthe textfields(ie Guardians name field) 

    I used this code but it gives the guid ...

    if (resultXml != null && resultXml.selectSingleNode('//q1:new_guardainname') != null) {

            var  ProjectName = resultXml.selectSingleNode('//q1:new_guardainname').nodeTypedValue;
                Xrm.Page.data.entity.attributes.get('new_guardain').setValue(ProjectName);
            }

    How to resolve this .. help me..?

    Thursday, December 1, 2011 12:52 PM

All replies

  • How to you get that resultXML?


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com
    Thursday, December 1, 2011 12:55 PM
  • here is my SOAP

    function RetrieveEntityById(prmEntityName, prmEntityId, prmEntityColumns) {

        var resultXml, errorCount, msg, xmlHttpRequest, arrayEntityColumns, xmlEntityColumns;

        arrayEntityColumns = prmEntityColumns.split(",");

        for (var i = 0; i < arrayEntityColumns.length; i++) {
            xmlEntityColumns += "<q1:Attribute>" + arrayEntityColumns[i] + "</q1:Attribute>";
        }

        var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

        //Prepare the SOAP message.
        var xml = "<?xml version='1.0' encoding='utf-8'?>" +
        "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
        " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
        " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
        authenticationHeader +
        "<soap:Body>" +
        "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
        "<entityName>" + prmEntityName + "</entityName>" +
        "<id>" + prmEntityId + "</id>" +
        "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
        "<q1:Attributes>" +
        xmlEntityColumns +
       "</q1:Attributes>" +
        "</columnSet>" +
        "</Retrieve></soap:Body></soap:Envelope>";

        //call function to create Soap Request to ms crm webservice
        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
        xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
        xmlHttpRequest.send(xml);

        resultXml = xmlHttpRequest.responseXML;

        var errorCount = resultXml.selectNodes('//error').length;

        if (errorCount != 0) {
            var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
            alert("Error Message : " + msg);
        }
        else {
            return resultXml;
        }
    }

    Friday, December 2, 2011 4:20 AM
  • try this logic

     

    if (resultXml != null && resultXml.selectSingleNode('//q1:new_guardainname') != null) {

            var  ProjectName = resultXml.selectSingleNode('//q1:new_guardainname');
                Xrm.Page.data.entity.attributes.get('new_guardain').setValue(ProjectName.text);

            }


    Guru Prasad
    Friday, December 2, 2011 6:31 AM
  • Hi,

    Try the segment code

    var ProjectName = resultXml.selectSingleNode('//q1:new_guardainname').nodeTypedValue;

     

    Regards,


    Philippe

    Blog : dynamicscrmcustomization

    Please remember to click "Vote as Helpful" and “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Proposed as answer by Philippe LEAL Wednesday, December 7, 2011 9:13 AM
    Wednesday, December 7, 2011 9:13 AM