Newb Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mattwi
    Junior Member
    • Mar 2023
    • 1

    Newb Question

    Hello,
    I have a an issue on how to do this :

    Customers(Accounts)
    Locations : each account have many locations
    Contracts: Each account can have a contract which contains one or many locations

    If i create for example a new contract and choose an Account , when i select a location i only want locations that belongs to the account selected
    as of now when i try to select a location , the linked field shows all the locations including the ones that don't belong to that acccount​...

    Any suggestions?
  • Vadym
    Super Moderator
    • Jun 2021
    • 345

    #2
    Hi Mattwi,

    Provide screenshots of Customers, Locations, and Contracts records in detail view, so we can find the best solution for you.​

    Example:
    Click image for larger version  Name:	image.png Views:	0 Size:	141.5 KB ID:	88797

    Comment

    • rabii
      Active Community Member
      • Jun 2016
      • 1250

      #3
      Originally posted by Mattwi
      Hello,
      I have a an issue on how to do this :

      Customers(Accounts)
      Locations : each account have many locations
      Contracts: Each account can have a contract which contains one or many locations

      If i create for example a new contract and choose an Account , when i select a location i only want locations that belongs to the account selected
      as of now when i try to select a location , the linked field shows all the locations including the ones that don't belong to that acccount​...

      Any suggestions?
      you need to create a custom view for your location on the contract. try this below:

      1 - create a custom view for your locations field under contract, create a file in this path client\custom\src\views\contract\fields\locations. js and paste the code below
      Code:
      define('custom:views/contract/fields/locations', 'views/fields/link', function (Dep) {
      return Dep.extend({
      getSelectFilters: function () {
      if (this.model.get('accountId')) {
      return {
      'account': {
      type: 'equals',
      attribute: 'accountId',
      value: this.model.get('accountId'),
      data: {
      type: 'is',
      nameValue: this.model.get('accountName')
      }
      }
      };
      }
      },
      getCreateAttributes: function () {
      if (this.model.get('accountId')) {
      return {
      id: this.model.get('accountId'),
      name: this.model.get('accountName')
      }
      }
      }
      });
      });​​
      2 - add the custom view of your locations field under your entityDefs Contract.json (under custom\Espo\Custom\Resources\metadata\entityDefs\C ontract.json)
      Code:
      {
      "fields": {
      "locations": {
      "type": "link",
      "view": "custom:views/contract/fields/locations"
      }
      }
      }​​
      I am assuming that the name of the field is (locations) on contract. this should allow to filter only locations of the current contract's account.

      Hope this helps
      Rabii
      Web Dev

      Comment

      Working...