set related modules relate field value to the current modules custom relate field

Hello Everyone,

I have a requirement, to bet related modules fields and set to the current record.

I have four modules i.e. Objects, Sub-objects, Units and Projects. I have one to many relationships are:

Objects to Sub-objects module - one to many

Sub-objects to Units - one to many

Projects to Objects - one to many

I don't have direct relationship between Units to Objects module and Units to Project module.

Within Objects module, have subpanel for Sub-objects

Within Sub-objects module i have two fields:

1. Objects (Lookup)

2. Project (Custom relate field)

Within Units module, have three fields:

1. Sub-objects (Lookup) 

2. Project (Custom relate field)

3. Object (Custom relate field)

So, My question is that, when i am going to create any record for Units module. And on selection of Sub-object (lookup), How to get auto populating value to the Project and Object fields.

For ex. 

Object Module have one record named as "Test object one", with selected project (Custom relate field) is "Test Project one".

"Test object one" is linked with Sub-object module record name is "Test Sub-object one".

"Test Sub-object one" is linked with Units module record named is "Test Unit one".

 

And when I open any record from Units module named as "Test Unit one".  As per above information, here is one lookup field i.e. Sub-objects which is by default selected ("Test Sub-object one")

Now i want to auto-populate value to "Project" and "Object" field(Custom)

Project field should selected value is "Test Project one"

and 

Object field should selected value is "Test object one"

because its linked with each other.

To achieve this functionality. I have two options i.e. Dependency and Vardefs(Populate-list)

Using vardefs populate_list related objects name is displayed but only for few seconds.

Below are my vardefs file code:

$dictionary['Units_Units']['fields']['pb_part_objects_units_units_1_name']['populate_list']['obj_objects_pb_part_objects_1_name']='objects_name'; //populate SUB OBJECT module's OBJECT field to objects_c field of Unit module

$dictionary['Units_Units']['fields']['pb_part_objects_units_units_1_name']['populate_list']['obj_objects_pb_part_objects_1_id']='objects_id';

pb_part_objects is my Sub-objects module

obj_objects is my Objects module

units_units is my Unit module

 

Any one have solution for this.

Thanks in advance! Francesca Shiekh#

  • You need to create all the relationships between:

    • Project and Sub-Object
    • Project and Unit
    • Object and Unit

    After that you can setup the attribute populate_list on field link of strong entity and on field relate of the weak entity, that means

    For module Sub Object:

    Configure populate_list on field type link of Unit.

    This way, on creating an Unit from subpanel under Sub Object it will auto populate the relationship to Object and Project as well.

    For module Unit:

    Configure populate_list on field type relate of Sub Object.

    This way, on creating an Unit from the scrath and select a Sub Object it will auto populate the relationship to Object and Project as well.

    Take a look at modules/Contacts/vardefs.php for reference.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • I have done this via sugar dependency. I don't create relationship because i don't want subpanel. so i am going through dependency. To set value to relate field.

    Code are given below:

    In Part Object module, on selection of Object(lookup/ relationship) field set value to Project field(custom relate field with Project module)

    FilePath: custom/Extension/modules/PO_Part_Objects/Ext/Dependencies/set_project_name.php

    <?php

    $dependencies['PO_Part_Objects']['set_project_name'] = array(
    'hooks' => array("edit", "view"),
    'trigger' => 'true',
    'triggerFields' => array('obj_objects_po_part_objects_1'),
    'onload' => true,
    'actions' => array(
    array(
    'name' => 'SetValue',
    'params' => array(
    'target' => 'pro_projects_id_c',
    'value' => 'ifElse(not(equal(related($obj_objects_po_part_objects_1,"pro_projects_obj_objects_1pro_projects_ida"),"")),related($obj_objects_po_part_objects_1,"pro_projects_obj_objects_1pro_projects_ida"),"")',
    )
    ),
    array(
    'name' => 'SetValue',
    'params' => array(
    'target' => 'project_c',
    'value' => 'ifElse(not(equal(related($obj_objects_po_part_objects_1,"pro_projects_obj_objects_1_name"),"")),related($obj_objects_po_part_objects_1,"pro_projects_obj_objects_1_name"),"")',
    )
    ),
    )
    );

    In Units module, on selection of sub-object (lookup) field, set value to custom relate field for Project and Object field.

    <?php

    $dependencies['Units_Units']['set_project_and_object_name'] = array(
    'hooks' => array("edit", "view"),
    'trigger' => 'true',
    'triggerFields' => array('po_part_objects_units_units_1'),
    'onload' => true,
    'actions' => array(
    array(
    'name' => 'SetValue',
    'params' => array(
    'target' => 'obj_objects_id_c',
    'value' => 'ifElse(not(equal(related($po_part_objects_units_units_1,"obj_objects_po_part_objects_1obj_objects_ida"),"")),related($po_part_objects_units_units_1,"obj_objects_po_part_objects_1obj_objects_ida"),"")',
    )
    ),
    array(
    'name' => 'SetValue',
    'params' => array(
    'target' => 'object_c',
    'value' => 'ifElse(not(equal(related($po_part_objects_units_units_1,"obj_objects_po_part_objects_1_name"),"")),related($po_part_objects_units_units_1,"obj_objects_po_part_objects_1_name"),"")',
    )
    ),
    array(
    'name' => 'SetValue',
    'params' => array(
    'target' => 'pro_projects_id_c',
    'value' => 'ifElse(not(equal(related($po_part_objects_units_units_1,"pro_projects_id_c"),"")),related($po_part_objects_units_units_1,"pro_projects_id_c"),"")',
    )
    ),
    array(
    'name' => 'SetValue',
    'params' => array(
    'target' => 'project_c',
    'value' => 'ifElse(not(equal(related($po_part_objects_units_units_1,"project_c"),"")),related($po_part_objects_units_units_1,"project_c"),"")',
    )
    ),
    )
    );