Filter a Link field by foreign variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rabii
    commented on 's reply
    Hey Etienne,

    Did you managed to sort it out ? i am trying to achieve same thing but i can't figure out how to do it ?

    any help would be much appreciated.

    Many thanks

    Rabii

  • Etienne
    replied
    thank you.
    I try this today.

    Etienne

    Leave a comment:


  • tanya
    replied
    in getSelectFilters you use parameters as for link field used
    EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.


    but you need as for link-multiple

    Leave a comment:


  • Etienne
    replied
    Hello Tanya,

    thank you for your help.

    All uppercase are change now.
    i change in :
    \custom\Espo\Custom\Resources\metadata\entityDefs\ Opportunity.json
    {
    "fields": {
    "testbases": {
    "type": "linkMultiple",
    "view": "custom:views/opportunity/fields/testbase", XXX change here
    "layoutDetailDisabled": false,
    "layoutMassUpdateDisabled": false,
    "importDisabled": false,
    "noLoad": false,
    "isCustom": true
    }
    },
    "links": {
    "testbases": {
    "type": "hasMany",
    "relationName": "testbaseOpportunity",
    "foreign": "opportunities",
    "entity": "testbase", XXX change here
    "audited": false,
    "isCustom": true
    }
    }
    }


    and

    Espo.define('custom:views/opportunity/fields/testbase', 'views/fields/link-multiple-with-role', function (Dep) { XXX change here

    return Dep.extend({

    getSelectFilters: function () {
    if (this.model.get('accountId')) {
    return {
    'account': {
    type: 'equals',
    field: 'accountId',
    value: this.model.get('accountId'),
    valueName: this.model.get('accountName'),
    }
    };
    }
    },

    getCreateAttributes: function () {
    if (this.model.get('accountId')) {
    return {
    accountId: this.model.get('accountId'),
    accountName: this.model.get('accountName')
    }
    }
    }

    });

    });


    and i change the name of file : from Testbase.js to testbase.js

    The testbase entity has a account multi-link field.

    I have the same problem with change uppercase in views.

    have you a idea ?

    thank you.
    Etienne

    Leave a comment:


  • tanya
    replied
    don't use uppercase in views
    Does Testbase entity have account link field?

    Leave a comment:


  • Etienne
    replied
    Hello,

    I have a similar problem.
    I click on opportunity and i click on "add opportunity". I can select a account (ex: my_account) and when I click on contact, a panel "contact" open with a filter "account - equals - my_account"

    I would like to do the same with my proper entity "Testbase"

    I created an entity "Testbase" like "contact".
    I created a file \custom\Espo\Custom\Resources\metadata\entityDefs\ opportunity.json

    {
    "fields": {
    "testbases": {
    "type": "linkMultiple",
    "view": "custom:views/opportunity/fields/Testbase",
    "layoutDetailDisabled": false,
    "layoutMassUpdateDisabled": false,
    "importDisabled": false,
    "noLoad": false,
    "isCustom": true
    }
    },
    "links": {
    "testbases": {
    "type": "hasMany",
    "relationName": "testbaseOpportunity",
    "foreign": "opportunities",
    "entity": "Testbase",
    "audited": false,
    "isCustom": true
    }
    }
    }

    I created \client\custom\src\views\opportunity\fields\testba se.js

    Espo.define('custom:views/opportunity/fields/Testbase', 'views/fields/link-multiple-with-role', function (Dep) {

    return Dep.extend({

    getSelectFilters: function () {
    if (this.model.get('accountId')) {
    return {
    'account': {
    type: 'equals',
    field: 'accountId',
    value: this.model.get('accountId'),
    valueName: this.model.get('accountName'),
    }
    };
    }
    },

    getCreateAttributes: function () {
    if (this.model.get('accountId')) {
    return {
    accountId: this.model.get('accountId'),
    accountName: this.model.get('accountName')
    }
    }
    }

    });

    });

    now, when i click on "new opportunity" -> I select account (my_account) -> I click on Testbase, i have this.

    I forgot somethings ?

    thank you

    Etienne

    Leave a comment:


  • Etienne
    replied
    Hello,

    I have a similar problem.
    I click on opportunity and i click on "add opportunity". I can select a account (ex: my_account) and when I click on contact, a panel "contact" open with a filter "account - equals - my_account"

    I would like to do the same with my proper entity "Testbase"

    I created an entity "Testbase" like "contact".
    I created a file \custom\Espo\Custom\Resources\metadata\entityDefs\ opportunity.json

    {
    "fields": {
    "testbases": {
    "type": "linkMultiple",
    "view": "custom:views/opportunity/fields/Testbase",
    "layoutDetailDisabled": false,
    "layoutMassUpdateDisabled": false,
    "importDisabled": false,
    "noLoad": false,
    "isCustom": true
    }
    },
    "links": {
    "testbases": {
    "type": "hasMany",
    "relationName": "testbaseOpportunity",
    "foreign": "opportunities",
    "entity": "Testbase",
    "audited": false,
    "isCustom": true
    }
    }
    }

    I created \client\custom\src\views\opportunity\fields\testba se.js

    Espo.define('custom:views/opportunity/fields/Testbase', 'views/fields/link-multiple-with-role', function (Dep) {

    return Dep.extend({

    getSelectFilters: function () {
    if (this.model.get('accountId')) {
    return {
    'account': {
    type: 'equals',
    field: 'accountId',
    value: this.model.get('accountId'),
    valueName: this.model.get('accountName'),
    }
    };
    }
    },

    getCreateAttributes: function () {
    if (this.model.get('accountId')) {
    return {
    accountId: this.model.get('accountId'),
    accountName: this.model.get('accountName')
    }
    }
    }

    });

    });

    now, when i click on "new opportunity" -> I select account (my_account) -> I click on Testbase, i have this.

    I forgot somethings ?

    thank you

    Etienne

    Leave a comment:


  • joy11
    replied
    tarasm Thank you! This works!
    I figured it was something easy with the right syntax or key words. I would have never thought the type would be 'in'. Now I will try to tackle the text filter.

    Leave a comment:


  • tarasm
    replied
    It's pretty easy. Used Chrome DevTools to find the correct search parameters.
    Code:
    getSelectFilters: function () {            
                return {
                    'type': {
                        type: 'in',
                        value: ['Vendor']
                    }
                };            
            },
    Tested. It works fine.
    Last edited by tarasm; 08-29-2017, 01:46 PM.

    Leave a comment:


  • joy11
    replied
    I've tried to just focus on one part at a time now. I know that I can get the value to filter in the select by using the custom view and the entityDef. I'll worry about the text complete after I get the select menu to work.

    I'm able to get the words "Account Type" to show up in the selection menu for the Vendor link. It does not pick up any of the other information set in the js however and I'm unable to select Vendor. I am able to add the "Account Type" filter from the add fields and then select vendor that way, but I want to preset it.

    I'm assuming it is because I don't have this portion formed correctly, but any hint would be appreciated.

    getSelectFilters: function () {
    return {
    'Account Type': {
    type: 'anyOf',
    value: 'Vendor',
    }
    };
    }
    Last edited by joy11; 08-30-2017, 09:58 PM.

    Leave a comment:


  • joy11
    replied
    So if I create: custom/Espo/Custom/SelectManagers/Account.php

    <?php
    namespace custom\Espo\Custom\SelectManagers\Account;

    class Account extends \Espo\Modules\Crm\SelectManagers\Account
    {
    protected function filterVendor(&$result)
    {
    $result['whereClause'][] = array(
    'type' => 'Vendor'
    );
    }
    }

    The above code is similar to what was in the application/Espo/Modules/Crm/SelectManagers/Account.php

    I'm not sure how to call this function from my entity, CurrentProduct, for the linked field "vendor" which is linked to the Account Entity. I have 25,000+ Accounts and 75 of them are "Vendors". I only want the 75 Vendors to come up in the select or when typed in the field in my CurrentProduct entity's vendor field.

    All of the other examples I have seen are only for filtering other entities that already have an association with an account (like contacts etc) instead of filtering from a value defined in the account entity already. I've viewed every post in the forums which even remotely dealt with filters, but i'm not getting it to work. I'm not sure if I need to work with the view and entityDef or the SelectManager and the clientDef of my CurrentProduct entity, or now maybe the Account.php?
    Last edited by joy11; 08-25-2017, 09:21 PM.

    Leave a comment:


  • tarasm
    replied
    I think, you can add to a filter to an Account: custom/Espo/Custom/SelectManagers/Account.php. Examples located at application/Espo/Modules/Crm/SelectManagers/Account.php

    Leave a comment:


  • joy11
    replied
    I've been working with custom views that are .js and the custom entityDefs that are .json
    I'm not sure where to put this php so it is called/used. Do I create a function of vendorFilter in a Custom/SelectManagers/CurrentProducts/CurrentProducts.php
    then envoke that on the clientDefs? I've tried so many different things and read so many different forums looking for hints that I don't know what direction is correct.

    Will this allow me to populate the link's select field?
    Last edited by joy11; 08-22-2017, 03:23 PM.

    Leave a comment:


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

    Leave a comment:


  • joy11
    replied
    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?

    Leave a comment:

Working...