Need to get the phone number of the main contact in an opportunity

Answered Need to get the phone number of the main contact in an opportunity

  • Saturday, March 16, 2013 1:56 PM
     
     

    Hi there,

    I am using CRM 2011 online. I a neewby and need help for this problem please :

    In the opportunity form, I added a lookup field (schema name : notifiedby) to choose the person (contact) who notified the event. I have another text field (schema name : notifierphone) where I want to get the mobilephone number of that contact.

    Could anyone help please ?

    Regards

    yodo94

All Replies

  • Saturday, March 16, 2013 2:01 PM
     
     

    Hi there,

    I am using CRM 2011 online. I a neewby and need help for this problem please :

    In the opportunity form, I added a lookup field (schema name : notifiedby) to choose the person (contact) who notified the event. I have another text field (schema name : notifierphone) where I want to get the mobilephone number of that contact.

    Could anyone help please ?

    Regards

    yodo94

    I forgot to add that I would like to have it in JavaScript and to happen onchange of the lookup filed.

    Thank you again.

  • Saturday, March 16, 2013 2:41 PM
    Moderator
     
     Answered Has Code

    Try something like this (make sure the field names are accurate):

    function Contact_OnChange() {
        var contact = new Array();
        //verfiy field name is correct
        contact = Xrm.Page.getAttribute("new_notifiedby").getValue();
    
        if (contact == null) {
            return;
        }
    
        var serverUrl = Xrm.Page.context.getClientUrl();
        var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/ContactSet?$select=MobilePhone&$filter=ContactId eq guid'" + contact[0].id + "'";
    
        var retrieveReq = new XMLHttpRequest();
        retrieveReq.open("GET", oDataSelect, false);
        retrieveReq.setRequestHeader("Accept", "application/json");
        retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
        retrieveReq.onreadystatechange = function () {
            GetContactData(this);
        };
        retrieveReq.send();
    }
    
    function GetContactData(retrieveReq) {
        if (retrieveReq.readyState == 4) {
            if (retrieveReq.status == 200) {
                var retrieved = JSON.parse(retrieveReq.responseText).d;
                //verfiy field name is correct
                Xrm.Page.getAttribute("new_notifierphone").setValue(retrieved.results[0].MobilePhone);
            }
        }
    }
    As you would expect - bind Contact_OnChange to the OnChange event of the lookup.


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

  • Monday, March 18, 2013 5:20 AM
     
     Answered Has Code

    Hi,

    please go through this,

    function Contact_OnChange() {
        var contact = new Array();
        //verfiy field name is correct
        contact = Xrm.Page.getAttribute("new_notifiedby").getValue();
    
        if (contact == null) {
            return;
        }
    
        var serverUrl = Xrm.Page.context.getClientUrl();
        var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/ContactSet?$select=MobilePhone&$filter=ContactId eq guid'" + contact[0].id + "'";
    
        var retrieveReq = new XMLHttpRequest();
        retrieveReq.open("GET", oDataSelect, false);
        retrieveReq.setRequestHeader("Accept", "application/json");
        retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
        retrieveReq.onreadystatechange = function () {
            GetContactData(this);
        };
        retrieveReq.send();
    }
    
    function GetContactData(retrieveReq) {
        if (retrieveReq.readyState == 4) {
            if (retrieveReq.status == 200) {
                var retrieved = JSON.parse(retrieveReq.responseText).d;
                //verfiy field name is correct
                Xrm.Page.getAttribute("new_notifierphone").setValue(retrieved.results[0].MobilePhone);
            }
        }
    }

    • Marked As Answer by yodo94 Wednesday, April 24, 2013 3:32 PM
    •  
  • Monday, March 18, 2013 6:02 AM
     
     Proposed

    Hi,

    I think you can also do it using jsript initially get the guid of the lookup field selected record an then by using the if condition then retrive the field values which are required and set then in the related fields.

  • Monday, March 18, 2013 7:21 AM
     
     

    Hi ,

    Please check this below link it may help you !

    http://social.microsoft.com/Forums/en-US/crm/thread/2bd39113-29a6-431f-8650-06e58662b2c4


    With Regards Athul MT http://www.athulmt.blogspot.in/

  • Monday, March 18, 2013 7:25 AM
     
     Proposed

    Hi,

    You can retrieve the data of another entity(Contact) when you select the record in the lookup field using "Odata endpoints".

    This the link that when you select the record in lookup it will retrieve the data of particular record and display the data in the fields where we requried in the form. Follow the steps carefully in the below link..


    Prudveen D If the answer helped you, remember to mark it as answer.

    • Proposed As Answer by prudween Monday, March 18, 2013 7:26 AM
    •  
  • Monday, March 18, 2013 2:09 PM
     
     

    Thank you so much !!!

    It works fine.

  • Monday, March 18, 2013 2:10 PM
     
     

    Thank you so much.

    Just used JLattimer version and it works fine. I shall try yours as well.

  • Monday, March 18, 2013 2:11 PM
     
     
    Thank you for your comments.
  • Monday, March 18, 2013 2:12 PM
     
     

    Thank you so much.

    Just used JLattimer version and it works fine. I shall try yours as well.

  • Monday, March 18, 2013 2:13 PM
     
     
    Thank you so much for your input. I shall have a look at that too.
  • Tuesday, March 19, 2013 6:22 AM