Announcement

Collapse
No announcement yet.

Field type of "Link" to only list entities with a specific attribute

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

  • Field type of "Link" to only list entities with a specific attribute

    I'm wondering if I'm maybe overthinking this or if I am approaching it in the correct way.

    Basically, what the title says, I want to limit the options in the dropdown when selecting a related record to only the records that have a specific value as its status field.

    For example:
    I have one entity named "Accommodation", with a one-to-many relationship with another entity called "Lodge Units", which has a field "status". I want to only have the ones with status = available to be in the drop-down when selecting.

    I can do the actual SQL query and so would like to know which template file is responsible for the query that results in the dropdown, how I can edit it and how to make that edit "update-proof".

    Any suggestions? I already tried the free plugins "Enum-From-SQL" and "Enum-From-Metadata", and though they were promising I could not get it to work, and so I think I may be over-complicating the solution.

  • #2
    With the Enum-From-SQL you might uninstall it as it currently have vulnerability.

    With regard to the Status, I'm not sure if Dynamic Logic (the bottom section when you edit your field) and Foreign will work for as a workaround. I don't know any good way at the moment sorry.
    Last edited by espcrm; 06-11-2021, 05:15 AM.

    Comment


    • #3
      Thanks for the heads-up on the extension vulnerability.

      Not sure that I follow your suggestion, though. I'm looking for a way of setting an entity in a state where it is not available to be used as a related link from another entity.

      In other words, using a hotel as an example, if an "accommodation" is an event-based entity in a many-to-one relationship with an "apartment", I want to make it so that when an "apartment" status field goes from Available to Occupied, then subsequent "accommodations" cannot select this "apartment".

      It just seems that I'm missing something obvious here.

      Comment


      • espcrm
        espcrm commented
        Editing a comment
        I understand what you want to do, and would love for an easy solution to implement in our system too. It just that usually I can think of some workaround method. Unfortunately not for this thread.

    • #4
      Check this link regarding complex expressions https://forum.espocrm.com/forum/gene...1320#post71320, I think that may help

      Comment


      • #5
        Thanks for the link, it does look promising. To be sure, do you mean that I'm able to populate a dropdown of options from this select query?

        Comment


        • #6
          You're welcome,

          I don't know. I haven't tried it with enum or multiEnum (dropdown) fields, I asked yuri if the complex expressions could be used to perform queries involving other entities but haven't received an answer, and also, this facility is limited to non-storable read-only fields, so it may not be the solution for you

          Perhaps the best way, if you don't mind coding, is to create a custom enum field class and use the setupOptions function to code your custom logic to present available options..

          For an actual example of this implementation, you can look how Espo 'choose a default currency' dropdown field is defined: https://github.com/espocrm/espocrm/b...ncy-default.js

          For instructions on how to create a custom field class follow this link : https://docs.espocrm.com/development...ing-field-type

          Comment


          • #7
            Another possible solution, still requiring some coding, but probably far less complicated than writing your own field class, could be to use the dynamic handler class, to write logic that determines visibility and content of fields. https://docs.espocrm.com/development/dynamic-handler/

            For more options, like modifying css or using User values as conditions for field display or content, check this free extension. https://forum.espocrm.com/forum/deve...gic-conditions

            Comment

            Working...
            X