locked
Add Mobile and Home Phone to Phone Call Form RRS feed

  • Question

  • I don't know java, so I'm hoping someone is nice enough to provide the code I can paste into the form's OnLoad properties.  I'm attempting to add the Home Phone and Mobile Phone from the Contact Entity to the Phone Call Form (main application form).

    I've already created two new attributes in the Phone Call Entity and added them to the form (read only) .  The first one is "new_mobilephone " and has a display name of Mobile Phone.  The second is "new_homephone " and has a display name of Home Phone.

    The data for the new Phone Call Entity fields should be pulled from the Contact Entity.  The first one is called "mobilephone " and has a display name of Mobile Phone.  The second is called "telephone2 " and has a display of Home Phone.

    Thanks for helping!

    Saturday, June 19, 2010 6:06 PM

Answers

  • Hi,

    you can use below script to fetch information, just paste this code on phone call onload,

    Let me know if you are facing any issue regarding the same

    FetchContactInformation();
    function FetchContactInformation() {
        var contactid;
        if (crmForm.all.from.DataValue != null) {
            contactid = crmForm.all.from.DataValue[0].id;

            var authenticationHeader = GenerateAuthenticationHeader();

            // Prepare the SOAP message.
            var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
    authenticationHeader +
    "<soap:Body>" +
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entityName>contact</entityName>" +
    "<id>" + contactid + "</id>" +
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
    "<q1:Attributes>" +
    "<q1:Attribute>mobilephone</q1:Attribute>" +
    "<q1:Attribute>telephone2</q1:Attribute>" +
    "</q1:Attributes>" +
    "</columnSet>" +
    "</Retrieve>" +
    "</soap:Body>" +
    "</soap:Envelope>";
            // Prepare the xmlHttpObject and send the request.
            var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
            xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
            xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
            xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xHReq.setRequestHeader("Content-Length", xml.length);
            xHReq.send(xml);
            // Capture the result.
            var resultXml = xHReq.responseXML;

            // Check for errors.
            var errorCount = resultXml.selectNodes('//error').length;
            if (errorCount != 0) {
                var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
                alert(msg);
            }
            else {
                crmForm.all.new_mobilephone.DataValue = resultXml.selectSingleNode("//q1:mobilephone").nodeTypedValue;
                crmForm.all.new_homephone.DataValue = resultXml.selectSingleNode("//q1:telephone2").nodeTypedValue;

            }
        }
    }


    Mahain
    Monday, June 21, 2010 1:13 PM
    Moderator

All replies

  • Sorry but I can't provide the code for you (no time to do this). However, I can point you in the right direction I hope.

    You will need to make a web service call back to CRM using Javascript to get the relevant data. All that will be known in the Phone Call form is the Sender. You will supply the sender in a query to get the mobile phone and home phone numbers. Your javascript will also have to test that the sender is a contact because other sender types are possible.

    The CRM SDK has a section on using crm web services in javascript as do numerous blogs.

    Hope this gets you on the right path.

     

    Monday, June 21, 2010 12:51 PM
    Moderator
  • Hi,

    you can use below script to fetch information, just paste this code on phone call onload,

    Let me know if you are facing any issue regarding the same

    FetchContactInformation();
    function FetchContactInformation() {
        var contactid;
        if (crmForm.all.from.DataValue != null) {
            contactid = crmForm.all.from.DataValue[0].id;

            var authenticationHeader = GenerateAuthenticationHeader();

            // Prepare the SOAP message.
            var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
    authenticationHeader +
    "<soap:Body>" +
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entityName>contact</entityName>" +
    "<id>" + contactid + "</id>" +
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
    "<q1:Attributes>" +
    "<q1:Attribute>mobilephone</q1:Attribute>" +
    "<q1:Attribute>telephone2</q1:Attribute>" +
    "</q1:Attributes>" +
    "</columnSet>" +
    "</Retrieve>" +
    "</soap:Body>" +
    "</soap:Envelope>";
            // Prepare the xmlHttpObject and send the request.
            var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
            xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
            xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
            xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xHReq.setRequestHeader("Content-Length", xml.length);
            xHReq.send(xml);
            // Capture the result.
            var resultXml = xHReq.responseXML;

            // Check for errors.
            var errorCount = resultXml.selectNodes('//error').length;
            if (errorCount != 0) {
                var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
                alert(msg);
            }
            else {
                crmForm.all.new_mobilephone.DataValue = resultXml.selectSingleNode("//q1:mobilephone").nodeTypedValue;
                crmForm.all.new_homephone.DataValue = resultXml.selectSingleNode("//q1:telephone2").nodeTypedValue;

            }
        }
    }


    Mahain
    Monday, June 21, 2010 1:13 PM
    Moderator
  • Mahain -  Thanks for your help!  I pasted the above code into the OnLoad box on the Phone Call Form.  But I got the following error:

    contact With Id = e3166931-f767-de11-bc1a-001e0b46d40c Does Not Exist.

    I checked, and there was a contact for the Phone Call Activity. 

    This is exactly what I pasted into OnLoad, as copied from above:

    FetchContactInformation();
    function FetchContactInformation() {
        var contactid;
        if (crmForm.all.from.DataValue != null) {
            contactid = crmForm.all.from.DataValue[0].id;

            var authenticationHeader = GenerateAuthenticationHeader();

            // Prepare the SOAP message.
            var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
    authenticationHeader +
    "<soap:Body>" +
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entityName>contact</entityName>" +
    "<id>" + contactid + "</id>" +
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
    "<q1:Attributes>" +
    "<q1:Attribute>mobilephone</q1:Attribute>" +
    "<q1:Attribute>telephone2</q1:Attribute>" +
    "</q1:Attributes>" +
    "</columnSet>" +
    "</Retrieve>" +
    "</soap:Body>" +
    "</soap:Envelope>";
            // Prepare the xmlHttpObject and send the request.
            var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
            xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
            xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
            xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xHReq.setRequestHeader("Content-Length", xml.length);
            xHReq.send(xml);
            // Capture the result.
            var resultXml = xHReq.responseXML;

            // Check for errors.
            var errorCount = resultXml.selectNodes('//error').length;
            if (errorCount != 0) {
                var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
                alert(msg);
            }
            else {
                crmForm.all.new_mobilephone.DataValue = resultXml.selectSingleNode("//q1:mobilephone").nodeTypedValue;
                crmForm.all.new_homephone.DataValue = resultXml.selectSingleNode("//q1:telephone2").nodeTypedValue;

            }
        }
    }

    Monday, June 21, 2010 6:20 PM
  • Could you please tell from where you are creating phone call activity ??
    Mahain
    Monday, June 21, 2010 6:37 PM
    Moderator
  • Most of our Phone Activities are created using workflows.  Sometimes we manually create them from opportunities, or contacts.

    To test the code from above, I went to Workplace/Activities/Phone Call Activities and selected a few of them.  They all seemed to create the error. when opening an existing Phone Call Activity.

     

    Thanks!

     

    Monday, June 21, 2010 7:36 PM
  • Hi,

    "code I can paste into the form's OnLoad properties.  I'm attempting to add the Home Phone and Mobile Phone from the Contact Entity to the Phone Call Form (main application form)."

    Based on above requirement this code should worked if you have a valid contact in from field of phonecall activity.

    "contact With Id = e3166931-f767-de11-bc1a-001e0b46d40c Does Not Exist" getting this error means you have not selected a valid contact in from field. so you can change code as below to check for type also

      if (crmForm.all.from.DataValue != null && crmForm.all.from.DataValue[0].type=='contact')

    let me know



    Mahain
    Tuesday, June 22, 2010 2:36 AM
    Moderator
  • Hi,

    We're making progress!  I figured out that the last error was due to the from field not being a contact.  This is usually the case since these are outgoing phone call activities.  So I changed from to to, and it works fine, but only when the contact has both mobile and home phone numbers present. 

    If either home phone or mobile phone are missing, then I get the error "there was an error with this field's customized event.  Field: window   Event:  onload  Error: object required.

    Now we just need language in the code that says, "if there is no mobile or home phone, then ignore that particular field".

    Also, as Feridun Kadir kindly pointed out above, the to field isn't always a contact.  So it will always gives errors when to is not a contact.  The other entity field commonly found in to is a user.  So if we could just get it to check "users", or ignore it all together, that would be great.

    Thanks!

    Tuesday, June 22, 2010 2:27 PM
  • Hi,

    Just check the updated script, this script will only work if the sender will be a contact

    FetchContactInformation();
    function FetchContactInformation() {
     var contactid;
     if (crmForm.all.from.DataValue != null && crmForm.all.from.DataValue[0].typename=='contact') {
     contactid = crmForm.all.from.DataValue[0].id;
     var authenticationHeader = GenerateAuthenticationHeader();
     var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
    authenticationHeader +
    "<soap:Body>" +
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entityName>contact</entityName>" +
    "<id>" + contactid + "</id>" +
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
    "<q1:Attributes>" +
    "<q1:Attribute>mobilephone</q1:Attribute>" +
    "<q1:Attribute>telephone2</q1:Attribute>" +
    "</q1:Attributes>" +
    "</columnSet>" +
    "</Retrieve>" +
    "</soap:Body>" +
    "</soap:Envelope>";
     // Prepare the xmlHttpObject and send the request.
     var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
     xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
     xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
     xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
     xHReq.setRequestHeader("Content-Length", xml.length);
     xHReq.send(xml);
     // Capture the result.
     var resultXml = xHReq.responseXML;
    
     // Check for errors.
     var errorCount = resultXml.selectNodes('//error').length;
     if (errorCount != 0) {
     var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
     alert(msg);
     }
     else {
     if((resultXml.selectSingleNode("//q1:mobilephone")==null !!resultXml.selectSingleNode("//q1:telephone2")==null))
     alert('if there is no mobile or home phone, then ignore that particular field');
     
     if(resultXml.selectSingleNode("//q1:mobilephone")!=null)
     crmForm.all.new_mobilephone.DataValue = resultXml.selectSingleNode("//q1:mobilephone").nodeTypedValue;
     if(resultXml.selectSingleNode("//q1:telephone2")!=null)
     crmForm.all.new_homephone.DataValue = resultXml.selectSingleNode("//q1:telephone2").nodeTypedValue;
    
     }
     }
    }
    
    

     Updated Code

     


    Mahain
    Tuesday, June 22, 2010 2:43 PM
    Moderator
  • Thank you for the updated code.  Is there a way to make it work if the Recipient  is the contact, and not the Sender?
    Tuesday, June 22, 2010 4:09 PM
  • Hi,

    For that you need to change

     if (crmForm.all.from.DataValue != null && crmForm.all.from.DataValue[0].typename=='contact')

    with below line

    if (crmForm.all.to.DataValue != null && crmForm.all.to.DataValue[0].typename=='contact')


    Mahain
    Tuesday, June 22, 2010 4:17 PM
    Moderator