Problem with Create-Actions Dynamic Views (different views based on user)

While the solution described here works well for record views/inline edit and editing existing records
http://cheleguanaco.blogspot.com/2014/08/sugarcrm-customization-dynamic.html

I can't seem to apply the same concept to the creation of new records.
The drawer opens with the default record.php layout before the initialize function has completed...
create-actions.js custom code:
               
({
  extendsFrom: 'CreateActionsView',
  initialize: function(options){
    this._super('initialize', [options]);
      this._super('initialize', [options]);
      var self = this;
      //set the view depending on user
      var userBean = app.data.createBean('Users', {id: app.user.id});
      var request = userBean.fetch();
      request.xhr.done(function(){
         var u_support_group = userBean.get('support_group_c') ;
         self.meta = app.metadata.getView(self.module, 'record-cs');
         if (u_support_group == 'TS' || u_support_group =='TSJ' || u_support_group =='TSS'){
            self.meta = app.metadata.getView(self.module, 'record-ts');
         }else{
            self.meta = app.metadata.getView(self.module, 'record-cs');
         }
      });
  },
  render: function()
  {
    this._super('render');
    this.setBusinessUnit();
  },
  setBusinessUnit: function(){
    var self = this;
    var userBean = app.data.createBean('Users', {id: app.user.id});
    var request = userBean.fetch();
    request.xhr.done(function(){
       var u_support_group= userBean.get('support_group_c') ;
       self.model.set('case_department_c',u_support_group);
    });
  },
  _dispose: function() {
    this._super('_dispose');
  },
})
                                                                                               


also tried extending instead of replacing

self.meta = _.extend({}, app.metadata.getView(self.module, 'record-ts'), self.meta);

Any ideas?

FrancescaS
Parents
  • Hi FrancescaS, 

    I want to know if you find an answer for this, or how you did it?

    I'm having the same problem.

    Thanks.
  • Glad you got a solution, but have you tried:

      extendsFrom: 'CreateActionsView',

      initialize: function(options){

        this._super('initialize', [options]);

          this._super('initialize', [options]);

          var self = this;

          //set the view depending on user

          var userBean = app.data.createBean('Users', {id: app.user.id});

          var request = userBean.fetch();

          request.xhr.done(function(){

             var u_support_group = userBean.get('support_group_c') ;

             self.meta = app.metadata.getView(self.module, 'record-cs');

             if (u_support_group == 'TS' || u_support_group =='TSJ' || u_support_group =='TSS'){

                self.meta = app.metadata.getView(self.module, 'record-ts');

             }else{

                self.meta = app.metadata.getView(self.module, 'record-cs');

             }

    render: function()

      {

        this._super('render');

        this.setBusinessUnit();

      },

      setBusinessUnit: function(){

        var self = this;

        var userBean = app.data.createBean('Users', {id: app.user.id});

        var request = userBean.fetch();

        request.xhr.done(function(){

           var u_support_group= userBean.get('support_group_c') ;

           self.model.set('case_department_c',u_support_group);

        });

      },

      _dispose: function() {

        this._super('_dispose');

      },

          });

      },

    })

Reply
  • Glad you got a solution, but have you tried:

      extendsFrom: 'CreateActionsView',

      initialize: function(options){

        this._super('initialize', [options]);

          this._super('initialize', [options]);

          var self = this;

          //set the view depending on user

          var userBean = app.data.createBean('Users', {id: app.user.id});

          var request = userBean.fetch();

          request.xhr.done(function(){

             var u_support_group = userBean.get('support_group_c') ;

             self.meta = app.metadata.getView(self.module, 'record-cs');

             if (u_support_group == 'TS' || u_support_group =='TSJ' || u_support_group =='TSS'){

                self.meta = app.metadata.getView(self.module, 'record-ts');

             }else{

                self.meta = app.metadata.getView(self.module, 'record-cs');

             }

    render: function()

      {

        this._super('render');

        this.setBusinessUnit();

      },

      setBusinessUnit: function(){

        var self = this;

        var userBean = app.data.createBean('Users', {id: app.user.id});

        var request = userBean.fetch();

        request.xhr.done(function(){

           var u_support_group= userBean.get('support_group_c') ;

           self.model.set('case_department_c',u_support_group);

        });

      },

      _dispose: function() {

        this._super('_dispose');

      },

          });

      },

    })

Children
No Data