locked
CRM 2011 - Getting account name from Contact RRS feed

  • Question

  • Hi,

    I have a custom activity that looks up contacts and upon selecting a contact it populates the address fields with the corresponding fields from the contact. I'm having a problem with the Account Name or ParentCustomerId. The value of "alert(addressEntity.ParentCustomerId)" is coming back as [object Object].

    Am I calling the right method?

    Apologies as my Javascript isnt very strong and I just need to get the account name onto the custom form as well.

    I was hoping to get the Account GUID then make an oData call to the AccountSet to get the 'name' back.

    I hope this makes sense.

    Thanks.

    function addressChanged() {
        var addressid = Xrm.Page.getAttribute("kcc_samplecontactid").getValue();
     
        if (addressid != null) {
            retrieveAddress(addressid[0].id);
        }
    }
     
    function retrieveAddress(addressid) {
        var entity = "Contact";
        var select = "?$select=ParentCustomerId,Address1_Line1,Address1_Line2,Address1_Line3,Telephone1,Address1_City,Address1_StateOrProvince,Address1_PostalCode,MobilePhone"
        var oDataSelect;
    
        // build query string
        oDataSelect = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/" + entity + "Set(guid'" + addressid + "')" + select + "";
    
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: oDataSelect,
            beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
            success: function (data, textStatus, XmlHttpRequest) {
                // Use for a single selected entity
                ProcessReturnMsg(data.d);
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
            }
        });
    }
    
    function ProcessReturnMsg(addressEntity) {
        alert(addressEntity.ParentCustomerId);
       //Xrm.Page.data.entity.attributes.get("kcc_customername").setValue(addressEntity.ParentCustomerId);
       Xrm.Page.data.entity.attributes.get("kcc_address1").setValue(addressEntity.Address1_Line1);
       Xrm.Page.data.entity.attributes.get("kcc_address2").setValue(addressEntity.Address1_Line2);
       Xrm.Page.data.entity.attributes.get("kcc_address3").setValue(addressEntity.Address1_Line3);
       Xrm.Page.data.entity.attributes.get("kcc_telephone").setValue(addressEntity.Telephone1);
       Xrm.Page.data.entity.attributes.get("kcc_addresscity").setValue(addressEntity.Address1_City);
       Xrm.Page.data.entity.attributes.get("kcc_addresscounty").setValue(addressEntity.Address1_StateOrProvince);
       Xrm.Page.data.entity.attributes.get("kcc_addresspostcode").setValue(addressEntity.Address1_PostalCode);
       Xrm.Page.data.entity.attributes.get("kcc_mobile").setValue(addressEntity.MobilePhone);
        }
    }


    Monday, September 3, 2012 1:08 PM

Answers

All replies

  • Lookup is a complex datatype.

     try something like this

    addressEntity.ParentCustomerId.Name

    I hope this helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior Solution Architect HP Australia Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com


    • Proposed as answer by Amreek Singh Monday, September 3, 2012 1:27 PM
    • Edited by Amreek Singh Monday, September 3, 2012 1:28 PM
    • Marked as answer by toutski Monday, September 3, 2012 2:18 PM
    Monday, September 3, 2012 1:27 PM
  • Thank you so much.

    I tried .name and got an error and didnt try .Name

    Thanks again.

    Monday, September 3, 2012 2:18 PM