Quantcast
Channel: Microsoft Dynamics CRM
Viewing all articles
Browse latest Browse all 123975

Forum Post: RE: Copy email and phone number of contact to custom fields on Pipeline form

$
0
0

If you were creating your opportunity from the contact, then you could use a relationship map - but I see that's not going to work for you.

You'll need to:

1. Create a Javascript webresource

2. Add an onContactChange function with some code similar to (This is not tested, but it'll give you the general ideal)

var primaryContact = Xrm.Page.getAttribute("new_primarycontactid").getValue()[0].id;

// Get OData Endpoint

var serverUrl = Xrm.Page.context.getClientUrl();

var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/ContactSet(guid'"+ primaryContact + "')?$select=EMailAddress1,Telephone1";

// Get the related contact

var request = new XMLHttpRequest();

request.open("GET", oDataSelect, false);

request.setRequestHeader("Accept", "application/json");

request.setRequestHeader("Content-Type", "application/json;charset=utf-8");

request.onreadystatechange = function () {

   if (request.readyState == 4) {

       if (request.status == 200) {

           var response = JSON.parse(request.responseText).d;

           var email = response.results[0].EMailAddress1;

           var telephone = response.results[0].Telephone1;

           Xrm.Page.getAttribute("new_customemail").setValue(email);

           Xrm.Page.getAttribute("new_customtelephone").setValue(telephone);

       }

   };

}

3. Register an onchange handler on the opportunity contact lookup that calls this code.


Viewing all articles
Browse latest Browse all 123975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>