locked
how to get selected lookup record attributes in crm 2013 RRS feed

  • Question

  • Hi Everyone,

    Can anyone tell me how can i get email from lookup by using javascript?

    I have an entity name "new_buyer" and its attribute name "new_email". I want to get email of selected record in lookup name is "new_buyerlookup"


    Thursday, March 20, 2014 5:34 AM

All replies

  • check this link you can get an idea how to use it

    http://mileyja.blogspot.in/2012/02/create-email-activity-in-microsoft.html


    ms crm

    Thursday, March 20, 2014 5:45 AM
  • Hi Aamir,

    Check the below link..

    http://vikramxrm.blogspot.ae/2012/04/auto-populate-form-fields-with-selected.html

    other option :

    this example is from sdk. 

    function LoadEvent() 
    {
         var sLookupValue = new Array();
        if (Xrm.Page.getAttribute("new_lookupfield").getValue() == null)
        { return ""; }
        sLookupValue = Xrm.Page.getAttribute("new_lookupfield").getValue();
        if (sLookupValue[0] != null) {
            var vLookid = sLookupValue[0].id;
        retrieveAccount(vLookid)
        }
    }

    function retrieveAccount(vLookId) {
     SDK.JQuery.retrieveRecord(
         vLookId,
         "new_customentityname",
         null, null,
         function (customentitynametogetstate&iso) {      
    Xrm.Page.getAttribute("new_state/province").setValue((customentityname.new_customeentityField));
         },
         errorHandler
       );
    }

    function errorHandler(error) {
     alert(error.message);
    }

    You need to add supporting jquery, jquery1.4.1min and json files.

    Hope this helps..

    Thursday, March 20, 2014 5:49 AM
  • please tell me what is user_accounts in this code and how to modify this code for custom entity like "new_buyer"

    function GetEmail() {
        var account = Xrm.Page.getAttribute("parentaccountid").getValue();
        if (account === null || account === undefined) return;
    
        var req = new XMLHttpRequest();
        req.open('GET', encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" + account[0].id + "')?$select=EMailAddress1&$expand=user_accounts&undefined"), true);
        req.setRequestHeader('Accept', 'application/json');
        req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(req.responseText).d;
                    var EMailAddress1 = result.EMailAddress1;
                    alert(EMailAddress1);
                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    
    }

    Thursday, March 20, 2014 6:10 AM