Announcement

Collapse
No announcement yet.

Filter link field values

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

  • Filter link field values

    In the "Call" entity, I created a "contact" field.
    This field is linked to the "Contact" entity.

    Click image for larger version

Name:	image.png
Views:	514
Size:	16.0 KB
ID:	88536
    Currently, when I click on the select button, I open the modal window that lists all the contacts of the "Contact" entity :

    Click image for larger version

Name:	image.png
Views:	360
Size:	58.2 KB
ID:	88538

    But ​I would like, when I click on the select button of the field, to open the modal select-record window, already filtering on the name entered in the contact field (if it is empty, the window lists all the contacts as at present) like this :
    Click image for larger version

Name:	image.png
Views:	348
Size:	57.4 KB
ID:	88539

    I created a custom view select-record.js, called in Contact.json.

    Looking at the forum, I tried to set up two functions to perform this filter based on the "contact" field of the entity Call.

    getSelectFilters: function () {
    let userName = this.model.get('contactId');
    if (userName) {

    return {
    contact': {
    type: 'equals',
    value: userName,
    data: {
    type: 'is',
    nameValue: this.model.get('contactName'),
    },
    }
    };
    }

    return null;
    },

    getCreateAttributes: function () {
    if (this.model.get('contactId')) {
    return {
    contactId: this.model.get('contactId'),
    contactName: this.model.get('contactName'),
    }
    }

    return null;
    },​


    But it doesn't work, no filter is applied. Do you have a clue?
    Attached Files

  • #2
    I think I have to extend the field (link) not select-record.
    I replaced and modified the getSelectFilters function but it still doesn't work

    Comment


    • #3
      I am not really sure why you need such filter but i am happy to help, so folow steps below:

      1 - this is the content of the field (contact) i am assuming the name of the field is contact otherwise you need to change the name to the correct name
      Code:
      define('custom:views/solicitation/fields/contact', 'views/fields/link', function (Dep) {
      
      return Dep.extend({
      
      getSelectFilters: function () {
      if (this.model.get('contactId')) {
      return {
      'name': {
      type: 'equals',
      attribute: 'name',
      value: this.model.get('contactName'),
      data: {
      type: 'equals',
      nameValue: this.model.get('contactName')
      }
      }
      };
      }
      },
      
      getCreateAttributes: function () {
      if (this.model.get('contactId')) {
      return {
      id: this.model.get('contactId'),
      name: this.model.get('contactName')
      }
      }
      }
      
      });
      });​
      2 - add the custom field view under your entityDefs Solicitation.json (under custom\Esp\Custom\Resources\metadata\entityDefs\So licitation.json)
      Code:
      {
      "fields": {
      "contact": {
      "type": "link",
      "view": "custom:views/solicitation/fields/contact"
      }
      }
      }​
      Et Voila

      This should do the trick but remember that this filter will only work if the field contact has a value otherwise the list will be for all contacts.

      PS: The reason why we used name because ID is not accessible from the UI for security reason, so name should do the trick.

      Hope this helps
      Rabii
      Web Dev | Freelancer

      Comment


      • #4
        Thanks a lot. I will test your code and keep you informed

        Comment

        Working...
        X