locked
CRM 2011 Javascript - Getting opportunity potential account value for child record RRS feed

  • Question

  • Is it possible to get the potential account from the opportunity to pull into a child record? If so what is the best way to go about this. I am thinking javascript would do the trick for me and allow me to set the subject on the child record with the potential account name however I am not sure how to pull the potential account from a parent record using java script.

    Any assistance would be greatly appreciated.

    Many Thanks Jenn

    Wednesday, June 11, 2014 9:34 PM

Answers

  • An example of getting Account information is shown below. You can make a similar function to get your desired results. Thanks,

    function GetData() {
    var context = Xrm.Page.context;
    var EntityID = Xrm.Page.data.entity.getId();
    var serverUrl = context.getServerUrl();
    var ODataPath = serverUrl + “/XRMServices/2011/OrganizationData.svc”;
    var retrieveResult = new XMLHttpRequest();
    retrieveResult.open(“GET”, ODataPath + “/AccountSet?$filter=AccountId eq (guid’” + EntityID + “‘)&$expand=Account_CustomerAddress”, false);
    retrieveResult.setRequestHeader(“Accept”, “application/json”);
    retrieveResult.setRequestHeader(“Content-Type”, “application/json; charset=utf-8″);
    retrieveResult.send();
    if (retrieveResult.readyState == 4 /* complete */) {
    if (retrieveResult.status == 200) {
    var retrieved= this.parent.JSON.parse(retrieveResult.responseText).d;
    var Result = retrieved.results[0];
    //Field From Account
    alert(Result.Name);
    //fields from more address
    alert(Result.Account_CustomerAddress.results[0].Line1);
    }
    }

    }


    Raza Usmani Software Engineer

    • Proposed as answer by Raza Usmani Thursday, June 12, 2014 11:23 AM
    • Unproposed as answer by JenniferNHS Monday, June 16, 2014 1:21 PM
    • Marked as answer by JenniferNHS Wednesday, June 24, 2015 7:37 PM
    Thursday, June 12, 2014 11:22 AM

All replies

  • Hi,
    I'm not sure I understood correctly your requirement, but if you just want to copy inside the Opportunity form the account name inside the Topic field, you can use this script (inside the onchange event of the Potential Customer field)

    function SetTopic() {
       var account = Xrm.Page.getAttribute("customerid").getValue();
       if (account == null) {
          Xrm.Page.getAttribute("name").setValue(null);
       } else {
          Xrm.Page.getAttribute("name").setValue(account[0].name);
       }
    }

    this works for CRM 2011, CRM 2013 has some differences in field names


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Wednesday, June 11, 2014 9:57 PM
    • Unproposed as answer by JenniferNHS Monday, June 16, 2014 1:21 PM
    Wednesday, June 11, 2014 9:57 PM
  • Are you in opportunity product and what to access potential customer from opportunity ??, you can query your opportunity entity and can include customer field in your request and then can use it.

    You can use retrieve method for this please check SDK for sample to use retrieve with Odata.


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, June 12, 2014 10:20 AM
    Moderator
  • An example of getting Account information is shown below. You can make a similar function to get your desired results. Thanks,

    function GetData() {
    var context = Xrm.Page.context;
    var EntityID = Xrm.Page.data.entity.getId();
    var serverUrl = context.getServerUrl();
    var ODataPath = serverUrl + “/XRMServices/2011/OrganizationData.svc”;
    var retrieveResult = new XMLHttpRequest();
    retrieveResult.open(“GET”, ODataPath + “/AccountSet?$filter=AccountId eq (guid’” + EntityID + “‘)&$expand=Account_CustomerAddress”, false);
    retrieveResult.setRequestHeader(“Accept”, “application/json”);
    retrieveResult.setRequestHeader(“Content-Type”, “application/json; charset=utf-8″);
    retrieveResult.send();
    if (retrieveResult.readyState == 4 /* complete */) {
    if (retrieveResult.status == 200) {
    var retrieved= this.parent.JSON.parse(retrieveResult.responseText).d;
    var Result = retrieved.results[0];
    //Field From Account
    alert(Result.Name);
    //fields from more address
    alert(Result.Account_CustomerAddress.results[0].Line1);
    }
    }

    }


    Raza Usmani Software Engineer

    • Proposed as answer by Raza Usmani Thursday, June 12, 2014 11:23 AM
    • Unproposed as answer by JenniferNHS Monday, June 16, 2014 1:21 PM
    • Marked as answer by JenniferNHS Wednesday, June 24, 2015 7:37 PM
    Thursday, June 12, 2014 11:22 AM
  • Sorry gentlemen I dont think I explained this very well. We have a custom activity that is tied to the opportunity. It is being requested that I default the subject of the custom activity to the potential account listed on the opportunity record. We have the regarding set to the actual opportunity. I am not sure from the custom activity how to call the opportunity parent form and get the potential account field from this form to populate the subject.
    Thursday, June 12, 2014 1:01 PM