web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Using javascript saveandclose is not working to close the existing form

(0) ShareShare
ReportReport
Posted on by 3,634

By using following code snippet I can Save & Close existing form and then open new form with certain parameters. However, when I hit Save & close button on new form it close that as well but get back to the older form. It seems that older form wasn't closed.

Any idea, what I am missing to close the existing form?

function getAttrValues(orderAttr,entityName){
    try{
        Xrm.Page.data.entity.save();
        setTimeout(function(){Xrm.Page.data.save("saveandclose").then(loadNewForm(orderAttr,entityName), function(){})},3000);
    }
    catch(e){
        alert("Error: "+e.message);
    }
}

function loadNewForm(orderdBy,entityName){
        var parameters = {};
        var orderId = Xrm.Page.getAttribute(orderdBy).getValue()[0].id;
        var orderName = Xrm.Page.getAttribute(orderdBy).getValue()[0].name;

        parameters["param_orderid"] = orderId;
        parameters["param_ordername"] = orderName;
        parameters["param_bol"] = 1;

        Xrm.Utility.openEntityForm(entityName, null, parameters);
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Mosin,

    That is the default behavior when you save and close a form it will redirect you to the last form opened.

    Best Regards,

    Shahbaaz

  • CRM Develope Profile Picture
    894 on at

    Hello

    please replace following line as per your code

    Xrm.Utility.openEntityForm(entityName,orderId);

    Thanks

  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at

    Use this:

    Xrm.Utility.openEntityForm(entityname, recordid, null, options);

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Could you please share more details? when is this code getting executed? and what actualy is your requirement?

  • Mohsin Ali Profile Picture
    3,634 on at

    CRM Develpo and Rajkumar, thanks for your reply. But I need to open new form not specific record.

  • Mohsin Ali Profile Picture
    3,634 on at

    On custom button click it should grab parameters from existing form, close existing form and then open up a new form with parameter values populated. And then upon hitting save and close it should close the window.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    So if I am not wrong your code is working fine but when you are clicking Save & Close, it is again taking you to the old form where you have opened this form? If this then it is expected, the save & close form.

    What are you expecting when you click Save & Close? If you want to go back to the home page view then you can have your own custom button say close and go back to your view

    community.dynamics.com/.../248468

    Hope this helps.

  • Mohsin Ali Profile Picture
    3,634 on at

    I have following snippet at Save & Close; it only save the record but do not close window.

    function closeRecord(){

    Xrm.Page.data.entity.save();

    setTimeout(function(){

    var tempWindow = window.top.location.href;

    tempWindow.close(); },3000);

    }

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    You have added the script to save the revord amd close the revord on save & close button....Save & close does the same thing by default and it will go the last used form if you try to close the current form. What you need is aredirevt to some main page.

    In the above code try the below

    window.top.location.href = <amin url of your crm i.e https:\\crmorg.crm.dynamics.com>

    Hope this helps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans