locked
How to create a custom entity record using the values retrieved from iframe in crm 2011? RRS feed

  • Question

  • In Account form i have an iframe where you can enter 3 text field values and when clicking on save button on iframe i want to create a custom entity record retrieved using those values?
    Monday, July 22, 2013 8:26 AM

All replies

  • Hi jasmin,

    You can create a html web resource put 3 text boxes and a button. On clicking the button you can use REST endpoint to create the record.For that you can go through the following link.

    http://msdn.microsoft.com/en-us/library/gg309549.aspx


    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful" Thank you, DT

    Monday, July 22, 2013 9:58 AM
  • How to retrieve html controls in frame using javascript?

    Monday, July 22, 2013 10:23 AM
  • create a web page and populate it in iframe 

    below is code to integrate web page with ms crm 

    http://srmscrm.wordpress.com/2012/07/19/custom-aspx-page-for-ms-crm-2011/


    ms crm

    Monday, July 22, 2013 10:47 AM
  • Hi Jasmin,

    You don't need to retrieve any controls from iframe. Just create a html web resource and add the controls and do all the logics which is creating the record inside that web resource which will be again called on click of the save button.

    Here I am asuming that the save button is on the web resource itself.Otherwise if you want to create record directly on save of the CRM form.Then you can get the webresource control by the following code.

     var webResource= Xrm.Page.ui.controls.get("WebResource_Name").getObject().contentWindow;

    and then from that you can get the control by the following line of code.

    var txtBoxVal=webResource.document.getElementById("txtBox").innerHTML;

    Please mark it as answer if it solves your problem


    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful" Thank you, DT


    Monday, July 22, 2013 10:53 AM
  • I have created an html page with three textboxes and a save button.But i don't know how to retrieve the html control values through javascript web resource.
    Monday, July 22, 2013 10:53 AM
  • you can also do it through the html web resource 

    ms crm

    Monday, July 22, 2013 12:34 PM
  • This is my html page.Is this the correct way to call the javascript webresource.When i click on save button i want to create a custom entity record based on these values.

    <script type="text/javascript" src="getIframeText.js"></script>
    <head>
        <title>Previous History</title>
        <style type="text/css">
     
            #updt
            {
                font-weight:bold;
                font-family:Segoe UI;
                width: 220px;
            }
            #gfor
            { 
                font-family:Segoe UI;
                 font-weight:bold;
                width: 220px;
            }
            #budgt
            {
                font-family:Segoe UI;
                font-weight:bold;
                width: 220px;
            }
            #btn
            {
                font-family:Segoe UI, Tahoma, Arial;
                font-size:11px;
                height:20px;
                padding-right:5px;
                padding-left:5px;
                border-top-width:1px;
                border-right-width:1px;
                border-bottom-width:1px;
                border-left-width:1px;
                border-top-style:solid;
                border-left-style:solid;
                border-bottom-style:solid;
                border-right-style:solid;
                cursor:pointer;
                background-repeat:repeat-x;
                border-bottom-color:#666666;
                border-top-color:#666666;
                border-left-color:#666666;
                border-right-color:#666666;
                width: 88px;
            }
            .style1
            {
                width: 223px;
            }
            .style2
            {
             width:100%;
             height:100%;
             background-color:#e9edf1  
            }
        </style>
    </head>
    <body>
    <form id="history" class="style2">
    <table align="center"
        style="background-repeat: repeat-x; border-collapse: collapse;">
    <tr>
    <td> <label>Previously Used Product</label>  </td>
     <td class="style1">   <input type = "text"
                      id = "updt"
                      name = "usedpdt" /></td>     
        
    </tr>
    <tr>
    <td> <label>Want to Go For</label>  </td>
     <td class="style1">   <input type = "text"
                      id = "gfor"
                      name = "gofor" /></td> 
    </tr>
    <tr>
    <td> <label>Budget</label>  </td>
     <td class="style1">   <input type = "text"
                      id = "budgt"
                      name = "budget" /></td> 
    </tr>
    <tr>
    <td></td>
    <td class="style1">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button"
             id="btn"
               value="Save"
               onclick="getIframeText();"/>

    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    Tuesday, July 23, 2013 4:29 AM
  • When i click on save button on iframe nothing happens.
    Tuesday, July 23, 2013 4:43 AM
  • There's a couple of ways of doing this. As mentioned earlier, you can add a call to the REST endpoint into your javascript code - this could take the form information and create a new record with the values entered. There's loads of resources out there about how to do this - my favourite is linked below:

    http://garethtuckercrm.com/2011/01/18/how-to-view-ribbon-definitions-in-crm-2011-3/

    Alternatively, you could create 3 new attributes on the form which will take this information. You can then add some calls to them in your javascript in your iframe. You reference the attributes from the iframe javascript with the following line of code:

    window.parent.Xrm.Page.data.entity.attributes.get("attribute_name").setValue("Here is the value");

    In fact, adding the "window.parent." bit will let you access all of the CRM Xrm from your iframe. Once the values are in your entity, you can then do whatever you want with them in the CRM code but if the iframe ever happens to be run without being wrapped up in CRM, the javascript will error as, of course, the attributes you're referencing won't be there.

    I hope this helps.

    • Proposed as answer by Jon_Evans Tuesday, July 23, 2013 10:23 AM
    Tuesday, July 23, 2013 10:22 AM