I want to have a window pop up after a task is saved

I want the user to save a task and ifs its a certain task type (a custom field) then I need a popup window with the ID of the task on it like


This window has info for the user to fill out on another system so I cant automate it.

I have found many places I can put this window.open() but no where that has access to the newly created task's ID.

I wanted to add it to the saveAndClose()  but it still doesn't have access to the task id.

  • why not just provide calculated custom URL field https://www.whatever.com?id=TASK_ID as tasks custom field?

    Best Regards,
    Dmytro Chupylka

    We make work in Sugar CRM system faster, more convenient and efficient

  • Hi

    You could redirect the user to that URL after the save is completed by overriding the saveAndClose in your create.js controller:

       saveAndClose: function(){
            this.initiateSave(_.bind(function () {
                if (this.closestComponent('drawer')) {
                    app.drawer.close(this.context, this.model);
                } else {
                    app.navigate(this.context, this.model);
                var url = "http://www.whatever.com?id="+this.model.id;
         }, this));

    You need to add your condition on the task type, but you get the idea.

    Of course this is a bit "drastic" and potentially high maintenance because you're not extending the saveAndClose but overriding it.

    I've not done this myself and just quickly tested the theory (and it works), and there is probably a better way of doing this without overriding the entire method but it may be a starting point for you...


  • Good idea but I cant give them an excuse for not doing it.  If its just a link on the screen it will be forgotten.

  • Couldnt I just do a

    this._super('saveAndClose', [options]);
  • Yes, that makes sense, you'll just need to wait for the save to complete before you can get the id.

  • Yeah, I thought I had already tried that and it does work except the id of the task is not available that I can find.

    this.model.id = undefined

    this.model.get('id') = undefined

    Not sure how to get at it. I even tried putting it in a settimeout so it runs a few seconds later.

  • I think my example works because of two things:

    1. the custom code is inside the callback function so the initiateSave is completed before the callback executes and the id exists.

    2. the bind controls the scope of "this", so that "this" is indeed the same "this" that was just saved, including the id.

  • Sorry to be late to this party but I thought I'd put in my $0.02 (or £0.02 for the UK pop Slight smile ).

    I think  has put you on the right track with looking at a callback function but I also think there may be a better way to accomplish what you are trying.

    If you look at the code for the _saveModel() function in: ./clients/base/views/record/record.js you will find there is an optional callback function that can be called. Crucially for you, this only gets called a) if it exists and b) after the Save has completed successfully - so if there are any errors it doesn't get called.

    To use this, I believe you just need to declare a function in your own custom js code with the name used of: saveCallback(). Note this takes a parameter (true) in the core call so you need to add that in, I think this possibly indicates the success or failure but you might want to grep for other functions to see if they are used elsewhere (I'm afraid I haven't had time to do that yet!). If you declare this function inside your own custom/modules/Tasks/clients/base/views/record/record.js (or potentially in ./custom/modules/Tasks/clients/base/views/create/create.js if you only want it on a Create action specifically) then you can ensure it runs only when Tasks are saved. Also it means you are not overriding any core functions and therefore is more upgrade safe.

    As this will be inside the scope of the Task object and called after the successful Save event I believe the "this" will contain all the saved fields including the id you are after and the field you want to test against for the pop up.

    Unfortunately I have not had time to test this either but hopefully you might find your solution within this area.

    An alternative approach I have just thought of would be to look for the code that actions the "Success" alert popup you get when creating a new record as this is effectively the action you want to replicate. If you see where and how that is done you may be able to override it with your own pop up (this may or may not already use the above callback function somewhere!!).



  • unfortunately, if users are neither motivated nor forced to copy/click the value already available on the screen, they will always find an excuse despite any tech/dev efforts and interface attractions that could be offered to them - the solution is rather organizational 

    Best Regards,
    Dmytro Chupylka

    We make work in Sugar CRM system faster, more convenient and efficient

  • 's suggestion should put you on the right track for opening the window in a new tab, similar but much better than my solution.

    But, just as 's solution of providing a URL requires your user to actually click it and fill the form, opening an extra form requires your user to fill it and not ignore the extra tab on their browser.
    Both have the potential for your user to ignore Whatever.com.

    If you have to make it such that the user cannot wiggle out of entering that data to whatever.com you could consider adding a panel with custom fields for the information that needs to be entered and make those fields required for the particular type of task. 
    Also add a reference to the Whatever.com record in that panel (which may be a useful reference regardless of the method you use to fill things in).
    In an after-save logic hook, if the reference to Whatever.com field is empty, and the whatever custom fields are not, copy the data to Whatever.com and record the reference in your whatever reference field in Sugar.  (This will prevent the next save from running the after-save logic hook again.)
    If you don't want to keep the whatever.com data in Sugar, you can also empty those fields in Sugar once the Whatever.com reference is added.

    To add to the mix of options (there are always so many!) you could check out 's post on the iFrameDrawer (I just came across it today while looking for solutions for your problem - why reinvent the wheel when there is so much information out there)


    I have not tried it, but wouldn't it be nice if you could open your whatever.com page in an iFrame Drawer and make them fill it out right there without changing to a potentially-ignored tab?