Hi what I would like to so is this:
On a new opportunity, when the user selects an account, I want to automatically select the primary contact for that account into the opportunity account field.
I have a form even working on the onChange event for Account field on the opportunity field. I am successfully getting the primaryContact entity data back via a json call. However, when I assign the contactID to the opportunity form field parentcontactid nothing happens. I have updated the code to enter the business telephone as the opportunity title to prove that it is working.
do I need to do something different to set an entity instead of a simple field? the below code is called onChange for the Account field parentaccountid). getContact is the method first invoked.
Also is there a simple way to detect if you are inserting? I only want to run the code on inserts.
thanks in advance
james
function getResident() {
//Getting the Lookup object from the CRM Page
var ProjectObject = Xrm.Page.getAttribute("parentaccountid").getValue();
// Getting the GUID for the Project record
var ProjectNoID= ProjectObject[0].id;
//Stripping out the curly brackets
ProjectNoID = ProjectNoID.replace('{', '').replace('}', '');
//Checking if we have a project GUID Value
if (ProjectNoID != null) {
//Let’s create the Web Service URL
oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
//Call the project retrieve function
//commented out for themo
RetrieveProjectRecord(ProjectNoID, oDataPath);
}
}
function RetrieveProjectRecord(Id, ODataPath) {
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", ODataPath + "/AccountSet(guid'" + Id + "')/account_primary_contact", true);
//retrieveReq.open("GET", ODataPath + "/AccountSet(guid'" + Id + "')", true);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () {
retrieveProjectReqCallBack(this);
};
retrieveReq.send();
}
function retrieveProjectReqCallBack(retrieveProjectReq) {
if (retrieveProjectReq.status == 200) {
var retrievedProject = JSON.parse(retrieveProjectReq.responseText).d;
var ProjectName = retrievedProject.Telephone1;
var theID = retrievedProject.ContactId;
alert(ProjectName + ' id= ' + theID);
Xrm.Page.getAttribute("name").setValue(ProjectName);
Xrm.Page.getAttribute("parentcontactid").setValue('{'+theID+'}');
Xrm.Page.getAttribute("description").setValue('hiya');
} else {
alert("Error in Fetching data");
}
}
*This post is locked for comments
I have the same question (0)