locked
Automatically changing an existing contact's parent account information to a different parent account information. RRS feed

  • Question

  • Is it possible to automatically map the address and other fields of a different parent account to an existing contact's address fields with out having to input the data.   I know you can select a different parent account but I cannot figure out how to auto populate the fields.
    Tuesday, June 4, 2013 5:11 PM

Answers

  • Simply use a workflow which triggers on the change of the Parent customer field. Then, update the address fields of the contact from its new account.


    My Weblog | My Website

    Tuesday, June 4, 2013 5:16 PM
    Moderator
  • You could also use JavaScript attached to the OnChange event of the parent customer

    Something like:

    function Parent_OnChange() {
        var account = Xrm.Page.getAttribute("parentcustomerid").getValue();
    
        if (account == null) {
            return;
        }
    
        if (account[0].entityType != "account") {
            return;
        }
    
        var serverUrl = Xrm.Page.context.getClientUrl();
        var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/AccountSet?$select=Telephone1&$filter=AccountId eq guid'" + account[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 () {
            GetAccountData(this);
        };
        retrieveReq.send();
    }
    
    function GetAccountData(retrieveReq) {
        if (retrieveReq.readyState == 4) {
            if (retrieveReq.status == 200) {
                var retrieved = JSON.parse(retrieveReq.responseText).d;
                Xrm.Page.getAttribute("new_field").setValue(retrieved.results[0].Telephone1);
            }
        }
    }
    


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, June 4, 2013 5:29 PM
    Moderator

All replies

  • Simply use a workflow which triggers on the change of the Parent customer field. Then, update the address fields of the contact from its new account.


    My Weblog | My Website

    Tuesday, June 4, 2013 5:16 PM
    Moderator
  • You could also use JavaScript attached to the OnChange event of the parent customer

    Something like:

    function Parent_OnChange() {
        var account = Xrm.Page.getAttribute("parentcustomerid").getValue();
    
        if (account == null) {
            return;
        }
    
        if (account[0].entityType != "account") {
            return;
        }
    
        var serverUrl = Xrm.Page.context.getClientUrl();
        var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/AccountSet?$select=Telephone1&$filter=AccountId eq guid'" + account[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 () {
            GetAccountData(this);
        };
        retrieveReq.send();
    }
    
    function GetAccountData(retrieveReq) {
        if (retrieveReq.readyState == 4) {
            if (retrieveReq.status == 200) {
                var retrieved = JSON.parse(retrieveReq.responseText).d;
                Xrm.Page.getAttribute("new_field").setValue(retrieved.results[0].Telephone1);
            }
        }
    }
    


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, June 4, 2013 5:29 PM
    Moderator
  • Thank you Jason and Payman
    Tuesday, June 4, 2013 7:04 PM