locked
Associating Account/Contact Addresses with Appointment Record RRS feed

  • Question

  • Maybe I am missing something, but when I create an appointment from an account is there anyway to specify which account address I am going to visit for the appointment? An account might have 3 or more different addresses associated with it. When I am making an on-site appointment I would like to pick which address I am visiting so that the company can make hotel reservations around that location. I can't seem to find any easy way of doing this short of typing it the address manually.

    I'd like to just have a look up option to the address based on the account selected but I'm not seeing anything. Does anyone know how I could achieve this functionality?

    Thanks for any help,
    -Trevor

    Monday, December 30, 2013 10:14 PM

Answers

  • Hi,

    You need to call a CRM web service from the appointment form. There are a few ways to do this but for me the easiest way is to call the webservice using jscript. I had the same requirements. In my case I needed to get a phone number from a contact's phone numbers while scheduling a new phone call. I don't remember where I originally got the code, but here is my code (remember that I want to get the home,mobile and business phone numbers from the contact entity and you can change the values to fullfill your requirements)

    The first code is the function that you need to create. the function gets two parameters; contactId and fieldname. in your case this would be accountid and your address fieldname (you have multiple addresses and this will work)

    function GetContactPhoneNumber(ContactId,PhoneFieldName) {
        //alert("getcontact is being called");
        var resultXml;
        var telephoneNumber = null;
        var errorCount;
        var msg;
        var xmlHttpRequest;
        var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();
            //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>"+PhoneFieldName+"</q1:Attribute>" +
        "</q1:Attributes>" +
        "</columnSet>" +
        "</Retrieve></soap:Body></soap:Envelope>";
        //call function to create Soap Request to ms crm webservice
        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
        xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
        xmlHttpRequest.send(xml);
        resultXml = xmlHttpRequest.responseXML;
        var errorCount = resultXml.selectNodes('//error').length;
        if (errorCount != 0) {
            var msg = resultXml.selectSingleNode('//description').nodeTypedValue; //Process and display the results.
        }
        else {
            if (resultXml.selectSingleNode('//q1:'+PhoneFieldName) != null)
                telephoneNumber = resultXml.selectSingleNode('//q1:' + PhoneFieldName).nodeTypedValue;
        }
        return telephoneNumber;
    }

    Then you can create an address picker in your appointment form and on the change of it, call the function. here is how I call them

    function PhoneSelector_onchange() {
        var SelectedPhoneId = Xrm.Page.getAttribute("new_phone").getValue();
        if (Xrm.Page.getAttribute("regardingobjectid").getValue() != null) {
            var ContactId = Xrm.Page.getAttribute("regardingobjectid").getValue()[0].id;
        }
        else {
            alert("Please select a regarding person");
            return;
        }
        switch (SelectedPhoneId) {
            case 100000000:
                var SelectedPhoneNumber = GetContactPhoneNumber(ContactId, "telephone1");
                Xrm.Page.getAttribute("phonenumber").setValue(SelectedPhoneNumber);
                break;
            case 100000001:
                var SelectedPhoneNumber = GetContactPhoneNumber(ContactId, "telephone3");
                Xrm.Page.getAttribute("phonenumber").setValue(SelectedPhoneNumber);
                break;
            case 100000002:
                var SelectedPhoneNumber = GetContactPhoneNumber(ContactId, "telephone2");
                Xrm.Page.getAttribute("phonenumber").setValue(SelectedPhoneNumber);
                break;
            default:
                alert("nothing");
        }
    }

    Tuesday, December 31, 2013 9:51 PM

All replies

  • Hi,

    No, you are not missing anything. This is no native way in MSCRM to do what you are after. You can custom build this with the combination of JS, REST, and an a couple of custom attributes depending on your requirements.


    Ronald

    Tuesday, December 31, 2013 7:55 PM
  • Hi,

    You need to call a CRM web service from the appointment form. There are a few ways to do this but for me the easiest way is to call the webservice using jscript. I had the same requirements. In my case I needed to get a phone number from a contact's phone numbers while scheduling a new phone call. I don't remember where I originally got the code, but here is my code (remember that I want to get the home,mobile and business phone numbers from the contact entity and you can change the values to fullfill your requirements)

    The first code is the function that you need to create. the function gets two parameters; contactId and fieldname. in your case this would be accountid and your address fieldname (you have multiple addresses and this will work)

    function GetContactPhoneNumber(ContactId,PhoneFieldName) {
        //alert("getcontact is being called");
        var resultXml;
        var telephoneNumber = null;
        var errorCount;
        var msg;
        var xmlHttpRequest;
        var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();
            //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>"+PhoneFieldName+"</q1:Attribute>" +
        "</q1:Attributes>" +
        "</columnSet>" +
        "</Retrieve></soap:Body></soap:Envelope>";
        //call function to create Soap Request to ms crm webservice
        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
        xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
        xmlHttpRequest.send(xml);
        resultXml = xmlHttpRequest.responseXML;
        var errorCount = resultXml.selectNodes('//error').length;
        if (errorCount != 0) {
            var msg = resultXml.selectSingleNode('//description').nodeTypedValue; //Process and display the results.
        }
        else {
            if (resultXml.selectSingleNode('//q1:'+PhoneFieldName) != null)
                telephoneNumber = resultXml.selectSingleNode('//q1:' + PhoneFieldName).nodeTypedValue;
        }
        return telephoneNumber;
    }

    Then you can create an address picker in your appointment form and on the change of it, call the function. here is how I call them

    function PhoneSelector_onchange() {
        var SelectedPhoneId = Xrm.Page.getAttribute("new_phone").getValue();
        if (Xrm.Page.getAttribute("regardingobjectid").getValue() != null) {
            var ContactId = Xrm.Page.getAttribute("regardingobjectid").getValue()[0].id;
        }
        else {
            alert("Please select a regarding person");
            return;
        }
        switch (SelectedPhoneId) {
            case 100000000:
                var SelectedPhoneNumber = GetContactPhoneNumber(ContactId, "telephone1");
                Xrm.Page.getAttribute("phonenumber").setValue(SelectedPhoneNumber);
                break;
            case 100000001:
                var SelectedPhoneNumber = GetContactPhoneNumber(ContactId, "telephone3");
                Xrm.Page.getAttribute("phonenumber").setValue(SelectedPhoneNumber);
                break;
            case 100000002:
                var SelectedPhoneNumber = GetContactPhoneNumber(ContactId, "telephone2");
                Xrm.Page.getAttribute("phonenumber").setValue(SelectedPhoneNumber);
                break;
            default:
                alert("nothing");
        }
    }

    Tuesday, December 31, 2013 9:51 PM
  • You could create your own custom entity to hold addresses and then it could have appointments and other activities.

    Jamie Miley

    Check out RBA Today!

    Check out my about.me profile!
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!

    • Proposed as answer by san Sanz Thursday, January 2, 2014 5:22 AM
    Thursday, January 2, 2014 2:20 AM
    Moderator