how to redirect to related list insert screen after inserting a parent account

The subject sorta sums up my question.

Basically I want to be able to do any of the following:

1. Make a specific subpanel entry required after inserting a parent account.

OR

2. Redirect to subpanel insert screen after inserting a parent account.

Any of those 2 doable? I'm using the professional edition by the way.

Parents
  • Hi Doddy Amijaya

    I think you can do that, overwrite the record view, so the first time they got in there you call a navigate

    app.router.navigate("#module_name/create", {trigger: true});
    

    You can count the amount of records in the collections for that subpanel, so you execute it when there is no records.

    Hope it helps

  • Hi Gerardo,

    It works great!. However I am kind of stuck on getting the subpanel data.

    what would be the parameter for App.data.getRelatedModule()?

    that's how I am supposed to grab the subpanel record right?

  • Hi Doddy Amijaya,

    In the record view of the module you want to call the create, and has the subpanels i would use

    this.model._relatedCollections;
    

    there should exist all your subpanels.

    Also you can go into each of the collections and call their models

    _.each(this.model._relatedCollections.example_collection_name.models, function(model){
         console.log(model);
    });
    

    Hope it helps

    Dont forget to mark the comment as the answer if it solved your problem.

  • Hi Gerardo,

    It's weird when I print it to the console "this" works fine and I can see this.model.

    however if I try to print this.model it says undefined and consequently if I try this.model._relatedCollections the page would break and not event load.

    I thought it was a scope issue, so I tried this:

    var self = this;

    console.log(self.model._relatedCollections);

    still got an error because I am trying to access something from undefined object.

    I extend the record view for my opportunity so that it would redirect to the insert screen of my custom module which is 1-M with Opportunity.

    Update:

    I think I may have figured out the problem.

Reply
  • Hi Gerardo,

    It's weird when I print it to the console "this" works fine and I can see this.model.

    however if I try to print this.model it says undefined and consequently if I try this.model._relatedCollections the page would break and not event load.

    I thought it was a scope issue, so I tried this:

    var self = this;

    console.log(self.model._relatedCollections);

    still got an error because I am trying to access something from undefined object.

    I extend the record view for my opportunity so that it would redirect to the insert screen of my custom module which is 1-M with Opportunity.

    Update:

    I think I may have figured out the problem.

Children
  • Hi,

    If you know what the problem is you can share it with us.

    I think your problem is that you are executing the code in the wrong function, it wont work on the initialize function, it should be executed after render.

    some elements inside "this" wont exist till then.

    Hope it helps

  • Hi Gerardo,

    I have just finally figured it out. and you are right it's a timing issue.

    I have to use a setTimeout(function(){if(this.model._relatedCollections.CUSTOMLINKNAME.models.length == 0)App.router.navigate(.....);},1000};

    At first I had to use this.on('render',this._mycustomfunctionname,this) but when I tried inside initializations the customization still work.

    so it really is just a timing issue.

    Thanks so much for your help man!

  • Actually one last thing, I made a mistake when I said I want to redirect to an insert page of my related list.

    I actually meant redirect to the selection-list screen, where you can link an existing record.

    I tried these:

    App.router.navigate("#modulename/link"....)

    App.router.navigate("#modulename/selection"....)

    App.router.navigate("#modulename/selection-list"....)

    App.router.navigate("#modulename/list"....)

    but no luck.

  • Hi Doddy Amijaya

    In this case you can use a Drawer like so...

    app.drawer.open({
        layout:'subpanel-list',
        context:{
            module: data,
            conllection: collection,
            .
            .
            .
            .
            .
            .
        }
    });
    

    Global Action Menus and Drawers in Sugar 7 « Sugar Developer Blog – SugarCRM

    Hope it helps

  • thanks man. it did help!