locked
Closing the custom activity form after mark complete RRS feed

  • Question

  • I have created a custom activity entity. I need the form to get closed on click of  "Mark complete" button, after completion of all the functionalities of "Mark Complete".When we click on mark complete, "SaveAsCompleted" method is getting called which is OOTB functionality. By doing some trial and error and googling  some blogs, I found that  "SaveAsCompleted" behaves asynchronously. If I use Xrm.Page.ui.close() as the very next statement  to be executed after "SaveAsCompleted", I can never be sure that the record status is changed to completed. 

    I found one way, when we click on mark complete, once all the functionalities of mark complete are executed, the form gets reloaded. So I thought of capturing unload event before closing the form.

    Here is the code window.attachEvent("onbeforeunload",Xrm.Page.ui.close());

    The problem with the above code is it was not working on all the browsers.

    Is there any other alternatives that can be done to achieve this.

    Thanks.. 



    • Edited by sspra Thursday, May 10, 2012 11:24 AM
    Thursday, May 10, 2012 11:05 AM

Answers

  • You could implement your own "SaveAsCompleted" method which would behave synchronously (I didnt knwo the OOB one was async) and then you can safely close the window. I agree attaching to the unload event is risky because of browser. If you don;t want to implement that function in javascript you can always create your custome "Mark As Complete" button which will actually start a dialog which closes the activity (this is synchronous) and then you can also safely close the window.


    Gonzalo | gonzaloruizcrm.blogspot.com

    Thursday, May 10, 2012 12:14 PM
    Moderator

All replies

  • You can maybe look at 'addonsave' event in the XRM library.  Also, use alert messages to alert the status of the record.  Can you maybe post the code?

    Please vote if you find my post useful. Add me on Skype @ christo.skype1

    Thursday, May 10, 2012 11:19 AM
  • You could implement your own "SaveAsCompleted" method which would behave synchronously (I didnt knwo the OOB one was async) and then you can safely close the window. I agree attaching to the unload event is risky because of browser. If you don;t want to implement that function in javascript you can always create your custome "Mark As Complete" button which will actually start a dialog which closes the activity (this is synchronous) and then you can also safely close the window.


    Gonzalo | gonzaloruizcrm.blogspot.com

    Thursday, May 10, 2012 12:14 PM
    Moderator