locked
Showing a related entity's associated view in an on a form. Please note - this is not the requirement you think it is. RRS feed

  • Question

  • So, I have a new requirement today - hopefully someone with JavaScript expertise can help. It's a bit of a challenge I think.

    What I need is - on a form I want to show a related entity's associated view. Note - this is two jumps down, not one.

    Let me expand on this. Let's say we take the Account entity. An Account has a Contacts associated view. So, I can display this view on the front page of the Account form using the well known 'associated view within an iFrame' JavaScript (now a feature in CRM 2011). However, let say the contact entity has a 1:N relationship with 'Properties' showing the 'Properties a Contact owns'.

    What I want (and this is the tough bit) is to display, underneath the iFrame displayed above, another iFrame - This one containing the Properties of the Contact selected in the first iFrame .

    Essentially, taking the embeded view feature to the next level down, with some added code which changes the second view based on the record selected in the first.

    Clearly, this is difficult - no doubt. But, can it be done (without creating a custom aspx page)?

    Many thanks everyone, I'm sure this would be a feature widely used by the community if we could figure out how to do it.

    Alastor

    • Moved by Kimberlee Johnson Thursday, March 3, 2011 10:37 PM Java Script question (From:Dynamics CRM)
    Thursday, March 3, 2011 10:02 PM

Answers

All replies

  • No takers?

    Friday, March 4, 2011 3:22 PM
  • Hi,

    Is it possible that you can create extra fields on the form where Iframe is. You can get the id of contact record when selected. Base on this id you can retreive the data of contact and show them in fields. Upon change of Data the related field will also change. You can also change the look and feel of fields.Please change fields and Iframe name according to your envoirnment.

    //***************************************
    //Button for Contact Selected
    //**********************
    var bFired = false;
    GridClickContact = function() {
     // check to see if this event has been fired already 
     if (bFired == false) {
     // get array of selected records 
     var frameDoc = document.getElementById("IFRAME_Contact").contentWindow.document;
     var a = frameDoc.all['crmGrid'].InnerGrid.SelectedRecords;
     var selectedItems = new Array(a.length);
     for (var i = 0; i < a.length; i++) {
      selectedItems[i] = a[i][0];
     }
     // alert(selectedItems); 
     // bFired = true; 
     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\">" +
    GenerateAuthenticationHeader() +
    " <soap:Body>" +
    " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
    " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
    " <q1:EntityName>contact</q1:EntityName>" +
    " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
    " <q1:Attributes>" +
    " <q1:Attribute>contactid</q1:Attribute>" +
    " <q1:Attribute>fullname</q1:Attribute>" +
    " <q1:Attribute>parentcustomerid</q1:Attribute>" +
    " </q1:Attributes>" +
    " </q1:ColumnSet>" +
    " <q1:Distinct>false</q1:Distinct>" +
    " <q1:Criteria>" +
    " <q1:FilterOperator>And</q1:FilterOperator>" +
    " <q1:Conditions>" +
    " <q1:Condition>" +
    " <q1:AttributeName>contactid</q1:AttributeName>" +
    " <q1:Operator>Equal</q1:Operator>" +
    " <q1:Values>" +
    " <q1:Value xsi:type=\"xsd:string\">" + selectedItems + " </q1:Value>" +
    " </q1:Values>" +
    " </q1:Condition>" +
    " </q1:Conditions>" +
    " </q1:Criteria>" +
    " </query>" +
    " </RetrieveMultiple>" +
    " </soap:Body>" +
    "</soap:Envelope>";
     var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
     xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
     xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
     xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
     xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
     xmlHttpRequest.send(xml);
     var resultXml = xmlHttpRequest.responseXML.xml;
     //alert(resultXml );
    
     if (resultXml != null || resultXml != "") {
      var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
      var bLoaded = xmlDocument.loadXML(resultXml);
      if (bLoaded) {
      var businessEntities = xmlDocument.getElementsByTagName('BusinessEntity');
    
    
      try {
       var oDiscount = xmlDocument.selectSingleNode("//BusinessEntity/q1:fullname").text;
       var oAccId = xmlDocument.selectSingleNode("//BusinessEntity/q1:parentcustomerid").text;
       var oAccName = xmlDocument.selectSingleNode("//BusinessEntity/q1:parentcustomerid").getAttribute("name");
       var lookupItem1 = new Array();
       lookupItem1[0] = new LookupControlItem(oAccId, 1, oAccName);
       crmForm.all.new_accountid.DataValue = lookupItem1;
    
    
       var lookupItem = new Array();
       lookupItem[0] = new LookupControlItem(selectedItems, 2, oDiscount);
       crmForm.all.new_contactid.DataValue = lookupItem;
      }
      catch (err) {
      }
      }
     }
    
     }
     else {
     // toggle our fired flag back 
     bFired = false;
     }
    }
    
    //To change format of data field
    crmForm.all.new_officeaddress.style.fontSize = '12px';
    crmForm.all.new_officeaddress.style.fontFamily= 'Arial Narrow' ; 
    crmForm.all.new_officeaddress.style.fontWeight= 'bold' ;
    crmForm.all.new_officeaddress.style.backgroundColor = "#EAF3FF";
    crmForm.all.new_officeaddress.style.borderColor = "#EAF3FF";
    crmForm.all.new_officeaddress.style.textDecoration = 'underline' 
    

    Regards Faisal
    • Proposed as answer by Jim Glass Jr Tuesday, March 8, 2011 9:05 PM
    Friday, March 4, 2011 8:06 PM
  • Saturday, March 5, 2011 3:48 PM
  • Hey Faisal, this looks great. Where do you hold in CRM?
    Tuesday, March 8, 2011 2:36 PM
  • Just put on load of the form which contains iframe. Change iframe name attribute names according to your requirement. You can save your energies by using service toolkit http://danielcai.blogspot.com/2010/05/mscrm4-web-service-toolkit-for.html an example is here also:- http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/16b5335b-3cc2-488d-b3d5-8a34ae7af019. You can add a section of four column to display data. You will get this option on the second tab when you create section. If you find any issue please feel free to contact.

     


    Regards Faisal
    Tuesday, March 8, 2011 2:50 PM