Announcement

Collapse
No announcement yet.

Filter a Link field by foreign variable

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

  • Filter a Link field by foreign variable

    I have a custom entity which has a Many-to-One relationship with the Account Entity. My Account Entity has a custom enum of "type" where I have different kinds of accounts I am keeping track of (i.e. Vendor, Customer, Agency)

    My custom entity has a link to the accounts where I'd like to select only accounts with the "type" of "Vendor". I've attached a screenshot of the select filter I'd like to have, but I'm not sure how to write it so that it works. I'm assuming it's something similar to what I'm working with already?


    I have created a custom view: **This does not work.** \client\custom\src\views\currentProduct\field\vend or.js

    Espo.define('custom:views/currentProduct/fields/vendor', 'views/fields/link', function (Dep) {

    return Dep.extend({

    getSelectFilters: function () {
    return {
    'account.type': {
    type: 'anyOf',
    value: 'Vendor',
    valueName: this.model.get('accountName'),
    }
    };
    }
    });

    });



    I've attached the custom view in custom/Espo/Custom/Resources/metadata/entityDefs/CurrentProduct.json

    {
    "fields": {
    "vendor": {
    "type": "link",
    "dynamicLogicVisible": null,
    "view": "custom:views/contract/fields/product",
    "required": false,
    "audited": false,
    "tooltip": false
    }
    },
    "links": {
    "vendor": {
    "type": "belongsTo",
    "foreign": "vendor",
    "entity": "Account",
    "audited": false,
    "isCustom": true
    }
    }
    }
    This is what filter i'd like to apply.
    Last edited by joy11; 08-11-2017, 01:57 PM.

  • #2
    Hello

    https://stackoverflow.com/questions/...20526#44820526
    https://github.com/espocrm/documenta...ustom-views.md


    needed path \client\custom\src\views\current-product\fields\vendor.js

    definition
    Code:
    Espo.define('custom:views/current-product/fields/vendor', 'views/fields/link', function (Dep) {
    in entityDefs field view has to be the same as in definition 'custom:views/current-product/fields/vendor'

    Comment


    • #3
      I'm sorry, I posted wrong entitydefs above.

      I have this in my custom/Espo/Custom/Resources/metadata/entityDefs/CurrentProducts.json :

      {
      "fields": {
      "vendor": {
      "type": "link",
      "dynamicLogicVisible": null,
      "view": "custom:views/currentProduct/fields/vendor",
      "required": false,
      "audited": false,
      "tooltip": false
      }
      },
      "links": {
      "vendor": {
      "type": "belongsTo",
      "foreign": "vendor",
      "entity": "Account",
      "audited": false,
      "isCustom": true
      }
      }
      }


      this does not work either. I think that my vendor.js isn't quite right? I'm not sure how to write it to only filter and display the accounts with type = "Vendor" (type is an enum added to accounts)

      Comment


      • #4
        using current-product instead of currentProduct is important. Check in browser log, if your view was read or you get 404 error

        Comment


        • #5
          You were right. It wasn't reading until I changed it to current-product. I am not getting any errors now and it's closer because something shows up as a filter. It still doesn't act quite like I thought it would.

          I've attached a screenshot of how the filter shows up currently. My enum from accounts is called "type" with label "Account Type". I'm not sure how to reference that value. This is what I have in the vendor.js view for that field.

          getSelectFilters: function () {
          return {
          'accountType': {
          type: 'anyOf',
          value: 'Vendor',
          valueName: this.model.get('accountName'),
          }
          };
          }

          Last edited by joy11; 08-11-2017, 07:08 PM.

          Comment


          • #6
            Is there a spot where I could just enter the mysql query to pull the accounts marked as vendors and have them selectable in the link drop-down? I'm trying to work within the parameters of the program, but this seems like it should be something very easy and is giving me problems for way too long.

            This is what I want to be able to select from the linked field: SELECT `id` FROM `account` WHERE `deleted` = 0 AND `type` LIKE 'Vendor'
            Anyone know how to do this?

            Comment


            • #7
              You can use the code;
              PHP Code:
              $accountList $entityManager->getRepository('Account')->where(array(    
                 
              'type' => 'Vendor',    
              ))->
              find(); 

              Comment

              Working...
              X