Default Primary Filter for assignedUser

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rouhu
    Member
    • Sep 2020
    • 39

    Default Primary Filter for assignedUser

    I have made a Primary Filter for Assigned User lookup values, added it to the filter list and it is working fine.
    But I cannot set it as default filter when used with child entity, no matter what.

    I have tried these at User.json:
    "filterList": [
    {
    "name": "ApprovingManager"
    }
    ],
    "selectDefaultFilters": {
    "filter": "ApprovingManager"
    },
    "defaultFilterData": {
    "primary": "ApprovingManager"
    }

    Tried also in child entity clientDefs:
    "relationshipPanels": {
    "assignedUser": {
    "layout": null,
    "selectPrimaryFilterName": "ApprovingManager",
    "filterList": ["ApprovingManager"]
    }
    }

    The assignedUser ​relationship is not in the list of relationships for an entity, so whats the name of the relationship ?

    Thanks for all.​
    Last edited by rouhu; 08-07-2024, 11:46 AM.
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #2
    filterName should be always be camelCase.

    PHP Code:
    {
    "filterList": [
            {
                "name": "approvingManager"
            }
        ],
    } 
    
    also in relationship panels

    PHP Code:
    "relationshipPanels": {
      "assignedUser": {
        "layout": null,
        "selectPrimaryFilterName": "approvingManager",
        "filterList": ["approvingManager"]
      }
    }

    see example in documentation https://docs.espocrm.com/development...tionshippanels
    Rabii
    Web Dev

    Comment

    • rouhu
      Member
      • Sep 2020
      • 39

      #3
      I did not define the filter with camelcase. But what I am really after is to pre-populate the assignedUser-field with userParentId-user.

      Here is the dynamic handler that just places the userParentId on to the assignedUser field but it needs something more. Any advice would be helpful ?

      Code:
      ​define('custom:approvingManager-handler', ['dynamic-handler'], (Dep) => {
      
      return class extends Dep {
      
      init() {
      
      if(!this.currUser) {
      this.currUser = this.recordView.getUser();
      }
      
      this.model.set('assignedUserId', this.currUser.get('userParentId') );
      
      }
      }
      });

      Comment

      • rouhu
        Member
        • Sep 2020
        • 39

        #4
        If you need to pre-populate form fields then here is working code:

        Code:
        define('custom:approvingManager-handler', ['dynamic-handler'], (Dep) => {
        
        return class extends Dep {
        
        init() {
        
        if(!this.currUser) {
        this.currUser = this.recordView.getUser();
        }
        
        if (this.currUser.get('userParentId')) {
        this.model.set('assignedUserId', this.currUser.get('userParentId') );
        
        Espo.Ajax.getRequest('User/'+this.currUser.get('userParentId'))
        .then(response => {
        if (!response || response.length === 0) {
        console.error('NO RESPONSE');
        return;
        }
        this.model.set('assignedUserName', response.name );
        // console.log('RESPONSE: ', response);
        })
        .catch(error => {
        console.error('ERROR:', error);
        
        });
        
        //this.model.set('assignedUserName', '[-- Leave Empty --]' );
        } else {
        this.model.set('assignedUserName', '[-- Select Approving Manager --]' );
        }
        }
        }
        });

        Comment

        • a.slyzhko
          Member
          • Oct 2023
          • 95

          #5
          The root cause of a problem lays down in views/fields/assigned-user.js file. If you look into its code you will find that filters are hadrcoded:
          PHP Code:
          getSelectBoolFilterList() {
              if (this.assignmentPermission === 'team') {
                  return ['onlyMyTeam'];
              }
          }
          
          getSelectPrimaryFilterName() {
              return 'active';
          }
          I defined custom js file for Task and used following code to resolve the same issue:
          PHP Code:
          define('custom:views/task/fields/assigned-user', ['views/fields/assigned-user'], function (Dep) {
          
              return Dep.extend({
          
                  getSelectPrimaryFilterName() {
                      return this.getMetadata().get(['clientDefs', 'Task', 'relationshipPanels', 'assignedUser', 'selectPrimaryFilterName'])
                          || this.getMetadata().get('clientDefs', 'User', 'selectDefaultFilters', 'filter')
                          || this.getMetadata().get('clientDefs', 'User', 'defaultFilterData', 'primary')
                          || 'active';
                  }
              })
          });
          

          Comment

          Working...