web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting Business phone number from Contact Subgrid

(0) ShareShare
ReportReport
Posted on by

Ok, so I am new to customizing CRM Dynamic 365 (on prem version).   I've downloaded the ribbon workbench and able to add a new button on the "CONTACT" screen.  I wrote a simple java script code for the button:

Alert("Hello");

And it works fine.  When I click on the button I see a pop up message "Hello".

Thus I went ahead trying to get the "business phone" of the SELECTED ROWS.  I've tried so may different code (where I found them using google search) and it is NOT working.  Here are some of the code I tried:

var rowData = Xrm.Page.getControl("Contacts").getGrid().getSelectedRows().get(0).getData();

var entity = rowData.getEntity();

var attributes = entity.getAttributes();

alert(attributes.get("telephone1").getValue());

The closest I ever got was using the code from ribbon workbench website itself:

https://ribbonworkbench.uservoice.com/knowledgebase/articles/129783-pass-the-currently-selected-grid-row-s-to-a-custo

which gives me the first column value and it seems this code only can get the "primary key" value of the subgrid, in the case, the company name.  But again, I need all other fields from the grid.

Any body have a working solution?

Thank you in advance!

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Seriously, 61 views, no answer?  I've seen many different code on this site and others, but they all don't work, although it may due to different version.  So from that, it seems there is a way to get it, just has to be a very specific way for crm 365?  Please if anyone knows, post the exact code to get the field content.

    Thank you!

  • Community Member Profile Picture
    on at

    Hi! 

    Try to use debugger in your code and press F12 in your page to view all attributes/values of entity/attributes.

    Hope this helps

     

    Vlad

    dynamicalabs.com

    Disclaimer: Any post on this page provided "as is" without warranty of any kind and is for educational and information purposes only. We disclaim any liability arising from any reliance placed on any post

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Frank,

    Tried this?

    www.magnetismsolutions.com/.../ahmed-anwar&;s-blog/2015/08/24/crm-2015-online---accessing-subgrid-data-using-javascript

  • Community Member Profile Picture
    on at

    sorry, but the link seems not working... but I saw your answer a while back to someone had same issue as I, and it didn't work... although again, that might been a older version of crm.  I thank you for your help as I see you tried to help alot of people (alot of crm search I did, you came up... :)

  • Community Member Profile Picture
    on at
  • Community Member Profile Picture
    on at

    So this is what I get when I debug my code, and it is very weird, why would it said can not get property for getGrid()??  I'm pretty sure my subgrid name is "contact", although I see alot of example code out there use "Contacts" which I tried too, but I get the same error.  Any thoughts?

    My code:" var rowData = Xrm.Page.getControl("contact").getGrid().getSelectedRows().get(0).getData();"

    The error I get: "Unable to get property 'getGrid' of undefined or null reference"

  • ashlega Profile Picture
    34,477 on at

    Hi,

     I think gridEntity is different from your regular entity - you can't get just any attribute:

    msdn.microsoft.com/.../dn932126.aspx

     You can use GridEntity to get the id, and, then, you'll need to use WebAPI to retrieve contact into.. somethind like this:

    function getContact(id) {

           var contactId = id.replace(/\{|\}/gi, "");

           var clientURL = Xrm.Page.context.getClientUrl();

           var req = new XMLHttpRequest();

           var query = "/api/data/v8.2/contacts("+contactId+")";

           req.open("GET", encodeURI(clientURL + query), true);

           req.setRequestHeader("Accept", "application/json");

           req.setRequestHeader("Content-Type", "application/json;charset=utf-8");

           req.setRequestHeader("OData-MaxVersion", "4.0");

           req.setRequestHeader("OData-Version", "4.0");

           req.onreadystatechange = function () {

               debugger;

               if (this.readyState == 4) {

                   req.onreadystatechange = null;

                   if (this.status == 200) {

                       var contact = JSON.parse(this.response);

                       alert(contact.telephone1);

                   }

                   else {

                       var error = JSON.parse(this.response).error;

                       alert("Error retrieving Record – " + error.message);

                   }

               }

           };

           req.send();

       }

    }

  • ashlega Profile Picture
    34,477 on at

    Although, I just noticed your second post.. Wondering what's the name of that grid since, apparently, it seems to be telling you that such control ("contacts") does not exist..

  • Community Member Profile Picture
    on at

    Alex,

    Thanks for the help.  Ya, I don't know either.  My CRM is fairly simply right now.  I've just installed CRM 2016 server from scratch, nothing special, no customization yet.  So all I do is that :

    1. I select "service"

    2. I select "contacts"

    3. I select a "row" on the contacts grid which currently is on "My Active Contacts"

    I used the code from ribbon workbench (link below):

    ribbonworkbench.uservoice.com/.../129783-pass-the-currently-selected-grid-row-s-to-a-custo

    And according to what the code return, I  got my "TypeName" as "contact" all lower case.  That's why I think my "subgrid name" is "contact", is it not correct?

    If so, what code or where about you would get the "proper name" for the subgrid in order for the code

    Xrm.Page.getControl("whatever suppose to be").getGrid()

    To work??

  • Community Member Profile Picture
    on at

    My ONLY purpose to do this is so that when the user "select" a row in Contact (or leads if I can even get contact to work), and that the press my "customized" ribbon button, I will get the "business phone" (or whever phone I deem to select) and I can sent out a HTTP post to the VoIP phone on their desk to make an out bound call.

    The VoIP phone we have is able to get command via HTTP post and do things (such as dial out).  

    I've figured out all the code such as which user login to use whatever IP and I also figure out how to do HTTP post command using javascript.  ALL THAT WORKS!  EXCEPT, this f***  (pardon my language) getting the phone number from the subgrid....

    The best thing I would like to do is to REPLACE the default function where when you click on the "phone" number, it automatically try to go to skype... if I can do OnClick event on the field....  But I read on other blog, they said that is NOT POSSIBLE to replace that feature and there is no OnClick event yet... someone did said to do OnChange, but I tried that, it don't work either...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans