locked
Save parent wondow RRS feed

  • Question

  • Hi,

    I want to save the parent page(crm entity form) on save of the child page(also a crm entity form), so I used below code on save of child page but none of them worked:

    window.top.opener.parent.Xrm.Page.data.entity.save();

    window.parent.opener.Xrm.Page.data.entity.save();

    Please let me know to do this? I am using ms crm 2011.

    Thursday, June 27, 2013 3:23 PM

All replies

  • You need to put this code in a function and call the function on save of child entity.


    Regards Faisal

    Thursday, June 27, 2013 3:32 PM
  • Thanks Faisal..As I said it is not working.
    Thursday, June 27, 2013 3:36 PM
  • I will suggest you to debug your code and see if you are getting parent entity object or not, it will be easy for you to implement this.

    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 27, 2013 4:48 PM
    Moderator
  • In the below code for the same, I just get alert 2 but the parent page is not saved. So, please help me with what should write to save the parent form.

    if ((window.top != null) && (window.top.opener != null) && (window.top.opener.parent != null) && (window.top.opener.parent.Xrm != null) && (window.top.opener.parent.Xrm.Page != null) && (window.top.opener.parent.Xrm.Page.data != null) && (window.top.opener.parent.Xrm.Page.data.entity != null)) {
    alert("1");
    window.top.opener.parent.Xrm.Page.data.entity.save();
    }
    else if((window.parent != null) && (window.parent.opener != null) && (window.parent.opener.Xrm != null))
    {
    window.parent.opener.Xrm.Page.data.entity.save();
    alert("2");
    }

    Friday, June 28, 2013 10:48 AM
  • In the below code for the same, I just get alert 2 but the parent page is not saved. So, please help me with what should write to save the parent form.

    if ((window.top != null) && (window.top.opener != null) && (window.top.opener.parent != null) && (window.top.opener.parent.Xrm != null) && (window.top.opener.parent.Xrm.Page != null) && (window.top.opener.parent.Xrm.Page.data != null) && (window.top.opener.parent.Xrm.Page.data.entity != null)) {
    alert("1");
    window.top.opener.parent.Xrm.Page.data.entity.save();
    }
    else if((window.parent != null) && (window.parent.opener != null) && (window.parent.opener.Xrm != null))
    {
    window.parent.opener.Xrm.Page.data.entity.save();
    alert("2");
    }


    I am using roll up 13
    Friday, June 28, 2013 11:42 AM

  • Why do you believe it is not saving.  I know this is an old question but thought I would add in case someone else is looking for an answer. Normally I do not add comments but I looked for a solution for my MS CRM 2011 issue for some time and in the end realized my code was OK but the system must have known there was nothing to save so it appeared it was not doing anything.

    First there are two different Parent saves.

    1) From a new form (Form Type 1) (Example. You just clicked the add Activity button on an Account)

    Use: window.parent.opener.Xrm.Page.data.entity.save();

    2) Open from Existing Form (Form Type 2)

    Use: window.top.opener.parent.Xrm.Page.data.entity.save();

    I have a custom Activity which calculates customer loyalty points then pushes the total back to the account for Account Reporting.  Until I added the "setSubmitMode("always")" line, the save seemed to do nothing because the system didn't really have anything to save.  I am not an expert by any means but thought this may help... if anyone has a better way to make the Parent save... let us know

      if (Xrm.Page.ui.getFormType()  != 1) {
        window.top.opener.parent.Xrm.Page.data.entity.attributes.get("new_loyaltypoints").setSubmitMode("always");
        window.top.opener.parent.Xrm.Page.data.entity.attributes.get("new_loyaltypoints").setValue(Xrm.Page.getAttribute("new_customertotal").getValue());
        window.top.opener.parent.Xrm.Page.data.entity.save();
      } else {
        window.parent.opener.Xrm.Page.data.entity.attributes.get("new_loyaltypoints").setSubmitMode("always");
        window.parent.opener.Xrm.Page.data.entity.attributes.get("new_loyaltypoints").setValue(Xrm.Page.getAttribute("new_customertotal").getValue());
        window.parent.opener.Xrm.Page.data.entity.save();
      }

    Thursday, July 2, 2015 9:01 PM