Menu

List add object filtering

GuillaumeF
2022-04-29
2022-05-02
  • GuillaumeF

    GuillaumeF - 2022-04-29

    Hello i've made some classes for ticketing management, like we want to do it.

    So i've made class MyUserRequest with a field describe like that:

                    <field id="physicalDevices_list" xsi:type="AttributeLinkedSetIndirect">
                        <linked_class>lnkPhysicalDeviceToMyTicket</linked_class>
                        <ext_key_to_me>ticket_id</ext_key_to_me>
                        <count_min>0</count_min>
                        <count_max>0</count_max>
                        <ext_key_to_remote>physicaldevice_id</ext_key_to_remote>
                        <duplicates/>
                    </field>   
    

    I've create the class lnkPhysicalDeviceToMyTicket describe like that:

            <class id="lnkPhysicalDeviceToMyTicket" _delta="define">
                <parent>cmdbAbstractObject</parent>
                <properties>
                    <is_link>1</is_link>
                    <category>bizmodel</category>
                    <abstract>false</abstract>
                    <key_type>autoincrement</key_type>
                    <db_table>lnkphisicaldevicetocdsticket</db_table>
                    <db_key_field>id</db_key_field>
                    <db_final_class_field/>
                    <naming>
                        <attributes>
                            <attribute id="ticket_id"/>
                            <attribute id="physicaldevice_id"/>
                        </attributes>
                    </naming>
                    <icon/>
                    <reconciliation>
                        <attributes>
                            <attribute id="ticket_id"/>
                            <attribute id="physicaldevice_id"/>
                        </attributes>
                    </reconciliation>
                </properties>
                <fields>
                    <field id="ticket_id" xsi:type="AttributeExternalKey">
                        <sql>ticket_id</sql>
                        <target_class>MyTicket</target_class>
                        <is_null_allowed>false</is_null_allowed>
                        <on_target_delete>DEL_AUTO</on_target_delete>
                    </field>
                    <field id="ticket_ref" xsi:type="AttributeExternalField">
                        <extkey_attcode>ticket_id</extkey_attcode>
                        <target_attcode>ref</target_attcode>
                    </field>
                    <field id="ticket_title" xsi:type="AttributeExternalField">
                        <extkey_attcode>ticket_id</extkey_attcode>
                        <target_attcode>title</target_attcode>
                    </field>
                    <field id="physicaldevice_id" xsi:type="AttributeExternalKey">
                        <sql>physicaldevice_id</sql>
                        <target_class>PhysicalDevice</target_class>
                        <is_null_allowed>false</is_null_allowed>
                        <on_target_delete>DEL_AUTO</on_target_delete>
                    </field>
                    <field id="physicaldevice_name" xsi:type="AttributeExternalField">
                        <extkey_attcode>physicaldevice_id</extkey_attcode>
                        <target_attcode>name</target_attcode>
                    </field>
                </fields>
                <methods>
                </methods>
                <presentation>
                    <details>
                        <items>
                            <item id="ticket_id">
                                <rank>10</rank>
                            </item>
                            <item id="physicaldevice_id">
                                <rank>20</rank>
                            </item>
                        </items>
                    </details>
                    <search>
                        <items>
                            <item id="ticket_id">
                                <rank>10</rank>
                            </item>
                            <item id="physicaldevice_id">
                                <rank>20</rank>
                            </item>
                        </items>
                    </search>
                    <list>
                        <items>
                            <item id="ticket_id">
                                <rank>10</rank>
                            </item>
                            <item id="physicaldevice_id">
                                <rank>20</rank>
                            </item>
                        </items>
                    </list>
                </presentation>
            </class>
    

    It's okay it's working but when i edit the Ticket, in the tab PhysicalDevices list, when i clic on the button " ADD PHYSICAL DEVICE OBJECTS" it's open a popin.
    But i've all phisical device, and i want to have a default filtering on the location_id (that i've in physicial device and in the class MyTicket).

    If anyone know how do that, i would like to know how.

    Thanks
    Guillaume F

     
  • Vincent @ Combodo

    Hi Guillaume,
    This can be done through a method

     
  • GuillaumeF

    GuillaumeF - 2022-04-29

    Thanks for your answer but i have try it without success, so i wich class i have to put the prefill search form method?

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2022-04-29

    You mentioned MyUserRequest

     
  • GuillaumeF

    GuillaumeF - 2022-04-29

    Thanks it's work.

    But just one thing, when i change the location how to get the new location when i go to the physicaldevice tab, without saving between?

     
  • Vincent @ Combodo

    How do you get the location $this->Get('location'), then it should be up to date when you try to add a PhysicalCI, or maybe you need to set of your attribute "physicalDevices_list" a dependency on field "location_id", this might help.
    But changing the location won't remove already linked CI even if they are not compliant to your search criteria. If you want to prevent this, you will need to overwrite DoCheckToWrite

     
  • GuillaumeF

    GuillaumeF - 2022-05-02

    Hello,
    Thanks for your answer, it's works very well.

    I will use DoCheckToWrite to remove linked PhysicalDevice if the location have been changed.

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2022-05-02

    I think you might want to use AfterUpdate() (or also AfterInsert() ) instead, since then it's actually a successful change already.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.