Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: Getting Business phone number from Contact Subgrid

    Hi Frank,

    Please go through the below links

    these may help you

    community.dynamics.com/.../197326

    www.magnetismsolutions.com/.../crm-2015-online---accessing-subgrid-data-using-javascript

    Thanks

    Hemant

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Getting Business phone number from Contact Subgrid

    Hi Frank,

     open that form in the form designer, click on the subgrid control, and you will see the control name.. it depends, though, on whether you are talking about the subgrids or about those "associated" grids (you get there from the navigation.. to the right of the contact name)

     As to what that typecode is, it's not the name of the control, it's the entity name (which is "contact".. which is correct)

     You might actually try combining the code from that page (since you have "id-s" there) with the function I posted above to get the phone numbers..

  • RE: Getting Business phone number from Contact Subgrid

    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...

  • RE: Getting Business phone number from Contact Subgrid

    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??

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Getting Business phone number from Contact Subgrid

    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..

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Getting Business phone number from Contact Subgrid

    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();

       }

    }

  • RE: Getting Business phone number from Contact Subgrid

    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"

  • RE: Getting Business phone number from Contact Subgrid

    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... :)

  • Aileen Gusni Profile Picture
    Aileen Gusni 44,524 on at
    RE: Getting Business phone number from Contact Subgrid

    Hi Frank,

    Tried this?

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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans