locked
How to execute custom script after save of an entity form? RRS feed

  • Question

  • Hi Devs,

    The client side programming reference says:

    Forms for Updated entities don’t reload the page after the initial save creating a record or any subsequent saves. Therefore, the OnLoad event occurs only during the initial load of the form.

    Is there any way for us to execute custom script after a save of an entity form?

    I also tried something unsupported to detect an ajaxStop from the form's script as I believe a save would be an ajax operation, but it didn't work:

        parent.$(document).ajaxStop(function () {
            console.log("ajax stop detected");
        });


    Help please.



    blog: <a href="http://technologynotesforyou.wordpress.com">http://technologynotesforyou.wordpress.com</a> | skype: ali.net.pk


    • Edited by Khadim Ali Friday, June 10, 2016 8:08 PM
    Friday, June 10, 2016 8:06 PM

Answers

All replies

  • you can try after your custom code you can refresh your form forcefully.

    for your reference (http://missdynamicscrm.blogspot.com/2015/06/the-difference-xrmpagedatarefresh-vs-crm-utility-openentityform.html)

    Regards

    Ayaz


    Ayaz

    Sunday, June 12, 2016 10:20 AM
  • You can use setTimeOut to execute java script code after the save event.
     
    To achieve this you need to attach the following function on save event.
     
    function executeAfterSave()
                        {
                       //setTimeOut to refresh the page asynchronously after the save event
                        setTimeout(function () {
                                //refresh the page
                   Xrm.Page.data.refresh();
                           
                        }, 1000);
                    }
     

    Thanks,
    Sam


    Inogic | Blog | news@inogic.com

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

    Wednesday, June 15, 2016 11:52 AM
  • You can use setTimeOut to execute java script code after the save event.
     
    To achieve this you need to attach the following function on save event.
     
    function executeAfterSave()
                        {
                       //setTimeOut to refresh the page asynchronously after the save event
                        setTimeout(function () {
                                //refresh the page
                   Xrm.Page.data.refresh();
                           
                        }, 1000);
                    }
     

    Thanks,
    Sam


    Inogic | Blog | news@inogic.com

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

    This would be unstable in case the core save operation will take more than 1 second? I have seen cases where the save operation was taking around 10+ seconds due to SDK plugin step execution.

    Anyway, to workaround I have wrapped my script in a setInterval() of 3 seconds on the form load.


    blog: <a href="http://technologynotesforyou.wordpress.com">http://technologynotesforyou.wordpress.com</a> | skype: ali.net.pk


    • Edited by Khadim Ali Monday, June 27, 2016 1:22 PM
    Monday, June 27, 2016 1:21 PM
  • you can try after your custom code you can refresh your form forcefully.

    for your reference (http://missdynamicscrm.blogspot.com/2015/06/the-difference-xrmpagedatarefresh-vs-crm-utility-openentityform.html)

    Regards

    Ayaz


    Ayaz

    Thanks Ayaz. But I wanted to execute my script after save operation is completed. I needed a point to activate my code then.

    blog: <a href="http://technologynotesforyou.wordpress.com">http://technologynotesforyou.wordpress.com</a> | skype: ali.net.pk

    Monday, June 27, 2016 1:29 PM
  • Hi Khadim,

    Try below approaches

    Xrm.Page.data.entity.addOnSave([function reference])

    Open same record after save.

    Xrm.Utility.openEntityForm("entityname", "entityid", null);

    Hope it helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in


    Wednesday, June 29, 2016 12:55 AM
  • You can use in OnSave event of the form and write your code in successCallback

    Xrm.Page.data.refresh(save).then(successCallback, errorCallback);


    MaKeer | myencounterwithcrm.wordpress.com | CRM2011 User Settings Utility | CRM2011 Lookup Preview | CRM2011 Lookup Attribute Mapping | CRM2011 TreeView Control (Beta) | CRM2011 N:N Entity View (Beta) | CRM 2011 Global Quick Search (Beta)

    • Marked as answer by Khadim Ali Monday, July 18, 2016 6:16 PM
    Monday, July 11, 2016 4:28 AM