locked
Get field value on click of ribbon button RRS feed

  • Question

  • Hello,

    How to get a field value on click of ribbon button on home page grid of an entity. I'm able to get the guid of record on selecting using crm parameter. But i'm not able to get the value inside the record. I need to get the value of field in that record when i select a record (by checking the check box) and click button in ribbon. For example to i need to account name on click of button in home page grid ribbon once i select a record.


    Madhu Sudhan.M

    Saturday, November 24, 2012 8:42 AM

Answers

  • Hello,

    You could write JS to get the account name based on the GUID.
    Here is the sample code-

    function GetRecord(_Filter) {
        try {
            var _Result = null;
            var _EndPoint = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
            var _XMLHttpRequest = new XMLHttpRequest();
            _XMLHttpRequest.open("GET", _EndPoint + "/" + _Filter, false);
            _XMLHttpRequest.setRequestHeader("Accept", "application/json");
            _XMLHttpRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            var _Result = _XMLHttpRequest.send();
            if (_XMLHttpRequest.readyState == 4 && _XMLHttpRequest.status == 200) {
                _Result = this.parent.JSON.parse(_XMLHttpRequest.responseText).d;
            }
            return _Result;
        }
        catch (Err) {
            alert(Err);
            return;
        }
    }


    function GetAccountName() {
        var _RecordId = null;
        var _Columns = "Name";
        var _Entity = "Account";
        _RecordId = account record GUID
        var _Filter = "/" + _Entity + "Set?$select=" + _Columns + "&$filter=" + _Entity + "Id eq (guid'" + _RecordId + "')";
        var _Result = GetRecord(_Filter);
        if (_Result != null && _Result.results.length == 1) {
            if (_Result.results[0].Name != null) {
                alert(_Result.results[0].Name);
            }
           
        }
    }


    • Edited by _Vikram Saturday, November 24, 2012 1:36 PM
    • Proposed as answer by F.Kuyler Monday, November 26, 2012 6:19 AM
    • Marked as answer by Madhu-CRM Monday, November 26, 2012 12:13 PM
    Saturday, November 24, 2012 1:35 PM

All replies

  • Hi

    use this get from your javascript.

    xrm.page.data.entity.attributes.get(fieldname).getvalue;


    --- Best regards Henrik Skydtsgaard

    Saturday, November 24, 2012 9:08 AM
  • Hello,

    You could write JS to get the account name based on the GUID.
    Here is the sample code-

    function GetRecord(_Filter) {
        try {
            var _Result = null;
            var _EndPoint = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
            var _XMLHttpRequest = new XMLHttpRequest();
            _XMLHttpRequest.open("GET", _EndPoint + "/" + _Filter, false);
            _XMLHttpRequest.setRequestHeader("Accept", "application/json");
            _XMLHttpRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            var _Result = _XMLHttpRequest.send();
            if (_XMLHttpRequest.readyState == 4 && _XMLHttpRequest.status == 200) {
                _Result = this.parent.JSON.parse(_XMLHttpRequest.responseText).d;
            }
            return _Result;
        }
        catch (Err) {
            alert(Err);
            return;
        }
    }


    function GetAccountName() {
        var _RecordId = null;
        var _Columns = "Name";
        var _Entity = "Account";
        _RecordId = account record GUID
        var _Filter = "/" + _Entity + "Set?$select=" + _Columns + "&$filter=" + _Entity + "Id eq (guid'" + _RecordId + "')";
        var _Result = GetRecord(_Filter);
        if (_Result != null && _Result.results.length == 1) {
            if (_Result.results[0].Name != null) {
                alert(_Result.results[0].Name);
            }
           
        }
    }


    • Edited by _Vikram Saturday, November 24, 2012 1:36 PM
    • Proposed as answer by F.Kuyler Monday, November 26, 2012 6:19 AM
    • Marked as answer by Madhu-CRM Monday, November 26, 2012 12:13 PM
    Saturday, November 24, 2012 1:35 PM