Announcement

Collapse
No announcement yet.

Filter list view by current record

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filter list view by current record

    Hi,

    I have an entity Project. It has multiple links to an entity Project Document, one for Budget, for Proposal, for Report, etc.
    For each Project Document, the Project that it belongs to is set.

    Now in the Project, I want to be able to select e.g. the budget. I click the select Project document. It opens the (small) list view to select from a list of Project Documents.

    It shows me all project documents from all projects.
    I want it to show all project documents from only the project record that I am working in.

    I have tried:
    - A report filter with a runtime filter (doesn't work)
    - children - parent relationship (doesn't work)

    This seems like a very common use case. But I can't find a reference to how to set this up.
    Does this require coding, or is it possible in the UI?

    If it requires coding, is there a good documentation for it?

  • #2
    what do you mean by this ?

    > I have an entity Project. It has multiple links to an entity Project Document, one for Budget, for Proposal, for Report, etc.

    Why would you create multiple links between two entities, you could use a status field on project document and then apply filters when selecting.

    I am not sure i understand how you set this up, if you share some screenshot we might be able to help

    Comment


    • #3
      I guess he wants to filter the document modal, when choosing a linked document to the main entity. It is only necessary to apply filters to the list. But one has still to activate the filter, when the modal opens.
      There is a workaround to choose the filter automatically depending on the linked field, but I did not succeed in configure that function.
      I think, something like this: https://forum.espocrm.com/forum/gene...active-entries

      Comment


      • #4
        metadata > clientDefs > Project > relationshipPanels > budget > selectHandler




        Example for Account: https://github.com/espocrm/espocrm/b...ame-account.js

        Comment


        • #5
          yuri thanks. Should such a file be created in this directory?

          client/custom/modules/advanced/src/handlers/select-related/same-project.js

          Comment


          • rabii
            rabii commented
            Editing a comment
            should be this client/custom/src/handlers/select-related/same-project.js

        • #6
          Is there a way to print to $log from the selectRelatedHandler?

          Comment


          • #7
            Another question: the same-account example is to filter a select handler through a third entity (account).

            In my case, I don't have a third entity. I want to filter the selectHandler of projectDocument entity by the projectId from the project record.

            Relationships:
            Click image for larger version

Name:	image.png
Views:	297
Size:	23.2 KB
ID:	98580

            How would the selectHandler have to be created to do this?

            Comment


            • #8
              > Another question: the same-account example is to filter a select handler through a third entity (account).

              The same question: https://forum.espocrm.com/forum/deve...odel-attribute

              > Is there a way to print to $log from the selectRelatedHandler?

              The question is why you need it. The log is in the back-end. The handler is in the front-end (browser). Usually you need just console.log and check your browser console.

              Comment


              • #9
                Thanks yuri

                I am having a lot of trouble to get the basics of this working:

                This is in the clientDefs of Project.js

                Code:
                 "relationshipPanels": {
                        "trainings": {
                            "layout": null
                        },
                        "projectBudget": {
                            "layout": null,
                            "createAttributeMap": {
                                "projectId": "projectId",
                                "projectName": "projectName"
                            },
                            "selectHandler": "handlers/select-related/same-project"
                        }
                    },
                ​
                I have the same-project.js file in two locations:
                /var/www/html/client/custom/src/handlers/select-related/same-project.js
                /var/www/html/client/src/handlers/select-related/same-project.js

                I am getting this error
                Code:
                loader.js:900:
                GET https://XX/client/lib/transpiled/src/handlers/select-related/same-project.js?r=1697268291 404 (Not Found)
                The files are readable by the server user: www-data

                We are on Espo 8.0.3

                I tried rebuilding en clear cache. As well as opening it in a new incognito browser.


                Hope anyone can help, so I can actually start debugging.​
                Last edited by Maarten; 10-15-2023, 08:02 AM.

                Comment


                • #10
                  You missed the module name.

                  "selectHandler": "your-module-name:handlers/select-related/same-project"

                  Comment


                  • yuri
                    yuri commented
                    Editing a comment
                    If you put your customizations to the "custom", then use "custom" as the module name. Note that your handler should be in AMD, not ES6.

                    define('custom:handlers/select-related/same-project', [], () => {
                    rerurn class {

                    }
                    });
                    Last edited by yuri; 10-15-2023, 08:13 AM.

                • #11
                  Thanks for all the help. That did it.

                  For future reference, please find the javascript handler below:

                  Code:
                  define('custom:handlers/select-related/same-project', [], () => {
                  return class {
                      /**
                       * @param {module:model} model
                       * @return {Promise<module:handlers/select-related~filters>}
                       */
                      getFilters(model) {
                          let advanced = {};
                  
                          let projectId = null;
                          let projectName = null;
                  
                          if (model.get('id')) {
                              projectId = model.get('id');
                              projectName = model.get('name');
                          }
                  
                          if (projectId) {
                              advanced.project = {
                                  attribute: 'projectId',
                                  type: 'equals',
                                  value: projectId,
                                  data: {
                                      type: 'is',
                                      nameValue: projectName,
                                  },
                              };
                          }
                  
                          return Promise.resolve({
                              advanced: advanced,
                          });
                      }
                  
                  }
                  ​

                  Comment

                  Working...
                  X