locked
Create parent and child entities in iframe RRS feed

  • Question

  • I have created two related custom entities, one is parent and the other is the child (1 to many relationship).

    I would like to be able to create the parent record with the list of child records at the same time using an Iframe on the parent form.

    The usual practice ive seens is that the child entities in the iframe are only created after saving the parent and then enabling the editing of the child entities in the iframe.

    Any suggestions of how to accomplish this?

    Also, i need to create an editable grid where i can add multiple child records at the same time? any suggestions of how to do this?

    Thanks.

     

    Monday, May 4, 2009 11:38 AM

Answers

  • Hi Qeefahs,

    when you want to create child records without an existing created parent record you have to develop something on your own. I haven't seen anything in this direction as AddOn. Sorry.

    If is it fine for you to create child records when the parent record is already saved then these articles can be helpful for you:
    http://www.stunnware.com/crm2/topic.aspx?id=JS27
    http://www.stunnware.com/crm2/topic.aspx?id=JS14

    For editing existing records direcly from the grid you can use the following AddOn:
    http://www.c360.com/RecordEditor.aspx

    AFAIK you can not add additional records with this AddOn.

    Best regards,
    Jürgen
    Jürgen Beck

    Dipl. Kfm./Wirtschaftsinformatik
    MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
    Microsoft Certified Business Management Solutions Professional
    Microsoft Certified CRM Developer
    Microsoft Certified Trainer

    ComBeck IT Services & Business Solutions
    Microsoft Gold Certified Partner
    Microsoft Small Business Specialist

    Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors

    http://www.combeck.de
    Monday, May 4, 2009 12:44 PM
    Moderator
  • I will put the code on my blog later, you may add a iframe on the parent form. I give you the code which works for both 1:N and N:N relationship.

    The 1:N relationship needs these parameters in the request URL: oId, oType, security, tabSet
    The N:N relationship needs an extra parameter: roleOrd in the request URL, which has been involved in the code.


    function GetFrameSrc(tabSet)
    {
      if (crmForm.ObjectId != null)
      {
        var id = crmForm.ObjectId;
        var type = crmForm.ObjectTypeCode;
        var security = crmFormSubmit.crmFormSubmitSecurity.value;
        var path = document.location.pathname.substring(0, document.location.pathname.search("edit.aspx")) + "areas.aspx?";
    
        return (path + "oId=" + id + "&oType=" + type + "&security=" + security + "&tabSet=" + tabSet);
      }
      else
      {
        return "about:blank";
      }
    }
    
    var navId = "nav_new_new_myentity_account";//replace the ID
    
    if(document.getElementById(navId) != null)
    {
      var tmp = document.getElementById(navId).onclick.toString();
      tmp = tmp.substring(tmp.indexOf("'")+1, tmp.indexOf(";"));
      var loadArea = tmp.substring(0, tmp.indexOf("'"));
      var roleOrd =  (tmp.indexOf("roleOrd") == -1) ? -1 : tmp.substring( tmp.indexOf("roleOrd"), tmp.lastIndexOf("'")).replace("\\x3d", "=");
      crmForm.all.IFRAME_view.src = (roleOrd == -1) ? GetFrameSrc(loadArea) : GetFrameSrc(loadArea) + "&" + roleOrd;
    }
    The child entities can only be added once the parent entity has a valid GUID, so the above code has handled it already.


    To build up a editable grid, you have to build a custom aspx page to accomplish the function.
    Jim Steger and Mike Snyder has an example of editable grid in their new book: Programming Microsoft Dynamics CRM 4.0 

    Hope it helps.

    Cheers,
    Jim Wang


    Jim Wang - MVP Dynamics CRM - http://jianwang.blogspot.com , http://mscrm.cn
    Monday, May 4, 2009 12:59 PM
    Moderator
  • The following concept also applies to your requirement. Although the initial requirement is a 1:1 relationship it can be easily adopted using a 1:N scenario. http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/9da135b3-217b-4a49-88ef-98f1e9b69137

     


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    Monday, May 4, 2009 1:01 PM
  • to update/refresh a form you can use the following java script code

    window.location.reload();
    Thanks, Aarch
    • Proposed as answer by Aarch Tuesday, May 5, 2009 11:34 AM
    • Marked as answer by JuergenBeckModerator Wednesday, May 6, 2009 9:30 PM
    Tuesday, May 5, 2009 11:34 AM

All replies

  • Hi Qeefahs,

    when you want to create child records without an existing created parent record you have to develop something on your own. I haven't seen anything in this direction as AddOn. Sorry.

    If is it fine for you to create child records when the parent record is already saved then these articles can be helpful for you:
    http://www.stunnware.com/crm2/topic.aspx?id=JS27
    http://www.stunnware.com/crm2/topic.aspx?id=JS14

    For editing existing records direcly from the grid you can use the following AddOn:
    http://www.c360.com/RecordEditor.aspx

    AFAIK you can not add additional records with this AddOn.

    Best regards,
    Jürgen
    Jürgen Beck

    Dipl. Kfm./Wirtschaftsinformatik
    MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
    Microsoft Certified Business Management Solutions Professional
    Microsoft Certified CRM Developer
    Microsoft Certified Trainer

    ComBeck IT Services & Business Solutions
    Microsoft Gold Certified Partner
    Microsoft Small Business Specialist

    Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors

    http://www.combeck.de
    Monday, May 4, 2009 12:44 PM
    Moderator
  • I will put the code on my blog later, you may add a iframe on the parent form. I give you the code which works for both 1:N and N:N relationship.

    The 1:N relationship needs these parameters in the request URL: oId, oType, security, tabSet
    The N:N relationship needs an extra parameter: roleOrd in the request URL, which has been involved in the code.


    function GetFrameSrc(tabSet)
    {
      if (crmForm.ObjectId != null)
      {
        var id = crmForm.ObjectId;
        var type = crmForm.ObjectTypeCode;
        var security = crmFormSubmit.crmFormSubmitSecurity.value;
        var path = document.location.pathname.substring(0, document.location.pathname.search("edit.aspx")) + "areas.aspx?";
    
        return (path + "oId=" + id + "&oType=" + type + "&security=" + security + "&tabSet=" + tabSet);
      }
      else
      {
        return "about:blank";
      }
    }
    
    var navId = "nav_new_new_myentity_account";//replace the ID
    
    if(document.getElementById(navId) != null)
    {
      var tmp = document.getElementById(navId).onclick.toString();
      tmp = tmp.substring(tmp.indexOf("'")+1, tmp.indexOf(";"));
      var loadArea = tmp.substring(0, tmp.indexOf("'"));
      var roleOrd =  (tmp.indexOf("roleOrd") == -1) ? -1 : tmp.substring( tmp.indexOf("roleOrd"), tmp.lastIndexOf("'")).replace("\\x3d", "=");
      crmForm.all.IFRAME_view.src = (roleOrd == -1) ? GetFrameSrc(loadArea) : GetFrameSrc(loadArea) + "&" + roleOrd;
    }
    The child entities can only be added once the parent entity has a valid GUID, so the above code has handled it already.


    To build up a editable grid, you have to build a custom aspx page to accomplish the function.
    Jim Steger and Mike Snyder has an example of editable grid in their new book: Programming Microsoft Dynamics CRM 4.0 

    Hope it helps.

    Cheers,
    Jim Wang


    Jim Wang - MVP Dynamics CRM - http://jianwang.blogspot.com , http://mscrm.cn
    Monday, May 4, 2009 12:59 PM
    Moderator
  • The following concept also applies to your requirement. Although the initial requirement is a 1:1 relationship it can be easily adopted using a 1:N scenario. http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/9da135b3-217b-4a49-88ef-98f1e9b69137

     


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    Monday, May 4, 2009 1:01 PM
  • Thank you all for the answers suggested, I am thinking of another solution that i am testing currently,

    I use javascript to save both the parent and the child entities passing the id of the created parent entity to the child entities before saving.

    I have already tested this approach and it seems to work so far. The final remaining step is to "Refresh" the form to change the form status to "update" mode and to show the additional options in the toolbar.

    What do you think of the solution?

    Tuesday, May 5, 2009 10:42 AM
  • to update/refresh a form you can use the following java script code

    window.location.reload();
    Thanks, Aarch
    • Proposed as answer by Aarch Tuesday, May 5, 2009 11:34 AM
    • Marked as answer by JuergenBeckModerator Wednesday, May 6, 2009 9:30 PM
    Tuesday, May 5, 2009 11:34 AM