Initial_filter for pupup

@fab

Do you have data in variable $_REQUEST['<field_relate>_name_advanced']?

Did you not forget change name ‘<field_relate>_name_advanced’ on correct name?

Yes, the name is correct, $_REQUEST['<field_relate>_name_advanced'] returns the correct value only the first time, when the popup appears, then when I click the search button (with no value set), $_REQUEST['<field_relate>_name_advanced'] is empty

I don’t know if correct, anyway I modified the code like this:

if(!empty($_REQUEST['<field_relate>_name_advanced'])){
        $parametrs_advanced='`<field_relate>_name`="'.$_REQUEST['<field_relate>_name_advanced'].'"'; // example part of SQL WHERE
        $_REQUEST['request_data']=$_REQUEST['<field_relate>_name_advanced'];
    }else{
        $parametrs_advanced='<field_relate>_name="'.$_REQUEST['request_data'].'";// example part of SQL WHERE
    }

and it works, now the problem is the query, it gives me an error because it rightly doesn’t recognize the <field_relate>_name field within the Users form, since it is related field of my custom form, how do I tell it to refer to that field which is not in the Users form?

@fab

At first I decided that you know that you can to use variable $_REQUEST[‘request_data’]. But it isn’t correct.

I tested decision with saving data in variable $_SESSION.

if(!empty($_SESSION['popupMetaFilter'][$module_name][$_REQUEST['action']])&&empty($_REQUEST['name_advanced'])){
    $_REQUEST['name_advanced']=$_SESSION['popupMetaFilter'][$module_name][$_REQUEST['action']]['name_advanced'];
}else{
    $_SESSION['popupMetaFilter'][$module_name][$_REQUEST['action']]['name_advanced']=$_REQUEST['name_advanced'];
}

Don’t modify $popupMeta['whereStatement']=>''

I do not believe, it works great, in a few lines solved both problems!
You are great @p.konetskiy, thank you very much!!!

@p.konetskiy how to place this line code:

'displayParams' => 
    array (
      'initial_filter' => '&<field_relate>_name_advanced="+this.form.{$fields.<field_relate>.name}.value+"',
);

I want to test on my end, don`t know if it is applicable to my concern https://community.suitecrm.com/t/relate-field-auto-populate-related-result-on-other-field/86748.

@p.konetskiy please nevermind I was able to figure it out. But I have another question how I can set my popupdef field as a readonly field.?

    'searchInputs' => array (
  1 => 'name',
  4 => 'custom_province_c',
),
  'searchdefs' => array (
  'name' =>
  array (
    'name' => 'name',
    'width' => '10%',
  ),
  'custom_province_c' =>
  array (
    'type'=>'readonly',
    'studio' => 'visible',
    'label' => 'LBL_PROVINCE',
    'width' => '10%',
    'name' => 'custom_province_c',
    'value' =>''.$_REQUEST['province_name'].'',
  ),

@fab , hello bro, were you able to fix it? I was able to implement it but my problem is when you search the name on a popup view there will be no result even the names are existing.

<?php
if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
}else{
    $parameters_advanced='`dvt3_city_id_c`=""';// example part of SQL WHERE
}

But it will work if I set the parameters to $parameters_advanced = " ". Check sample code below:

<?php
if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
}else{
    $parameters_advanced='';// example part of SQL WHERE
}

The only disadvantage on this code is even there is no value on the province which is my first field, all the data on city popupdefs will display. The pre-filtered customization will be pointless if it will display all data of the city.

@waraikobuot, let me understand the problem, what are the modules you are working on, custom and…? What are you trying to achieve? Where are you making the changes?

I created total of 4 modules all of them are customs. I have a Location, Province, City and Barangay.

In location module I have 3 field a Province(Relate to Province Module), City(Relate to City Module) and Barangay(Relate to Barangay Module). If you click Province Field on the City Field there must be a Pre-filtered result. Check my sample result below:
image

This logic is working now using this code below: (But the data/result are not clickable)

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
    $_REQUEST['request_data'] = $_REQUEST['city'];
}else{
    $parameters_advanced='`dvt3_city_id_c`="'. $_REQUEST['request_data'].'"';// example part of SQL WHERE
}

For the Changes I added a displayparams on Custom Location Module
For City Relate Field in Location Module

            'name' => 'custom_city_c',
            'studio' => 'visible',
            'label' => 'LBL_CITY',
            'displayParams' => array(
                'initial_filter' => '&province="+this.form.{$fields.dvt2_province_id_c.name}.value+"&province_name="+this.form.{$fields.custom_province_c.name}.value+"',
              ),

For Barangay Relate Field in Location Module

'name' => 'custom_barangay_c',
            'studio' => 'visible',
            'label' => 'LBL_BARANGAY',
            'displayParams' => array(
              'initial_filter' => '&province_name="+this.form.{$fields.custom_province_c.name}.value+"&city="+this.form.{$fields.dvt3_city_id_c.name}.value+"&city_name="+this.form.{$fields.custom_city_c.name}.value+"',
             ),

And I modify the popupdefs for City and Barangay Module. Check the code below:

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
    $_REQUEST['request_data'] = $_REQUEST['city'];
}else{
    $parameters_advanced='`dvt3_city_id_c`="'. $_REQUEST['request_data'].'"';// example part of SQL WHERE
}
$popupMeta = array (
    'moduleMain' => 'dvt4_Barangay',
    'varName' => 'dvt4_Barangay',
    'orderBy' => 'dvt4_barangay.name',
    'whereStatement'=> "$parameters_advanced",
    'whereClauses' => array (
    'name' => 'dvt4_barangay.name',
),
    'searchInputs' => array (
  1 => 'name',
),
  'searchdefs' => array (
  'custom_province_c' =>
  array (
    'type' => 'readonly',
    'studio' => 'visible',
    'label' => 'LBL_PROVINCE',
    'id' => 'DVT2_PROVINCE_ID_C',
    'width' => '10%',
    'name' => 'custom_province_c',
    'value' =>''.$_REQUEST['province_name'].'',
  ),
  'custom_city_c' =>
  array (
    'type' => 'readonly',
    'studio' => 'visible',
    'label' => 'LBL_CITY',
    'id' => 'DVT3_CITY_ID_C',
    'width' => '10%',
    'name' => 'custom_city_c',
    'value' =>''.$_REQUEST['city_name'].'',
  ),
  'name' =>
  array (
    'name' => 'name',
    'width' => '10%',
  ),
),
    'listviewdefs' => array (
  'NAME' => 
  array (
    'width' => '32%',
    'label' => 'LBL_NAME',
    'default' => true,
    'link' => true,
    'name' => 'name',
  ),
  'CUSTOM_CITY_C' => 
  array (
    'type' => 'relate',
    'studio' => 'visible',
    'label' => 'LBL_CITY',
    'id' => 'DVT3_CITY_ID_C',
    'width' => '10%',
    'default' => true,
    'name' => 'custom_city_c',
  ),
  'CUSTOM_PROVINCE_C' => 
  array (
    'type' => 'relate',
    'studio' => 'visible',
    'label' => 'LBL_PROVINCE',
    'id' => 'DVT2_PROVINCE_ID_C',
    'width' => '10%',
    'default' => true,
    'name' => 'custom_province_c',
  ),
),

Samples result are correct already but the problem is when I click the result I am unable to populate the result to the barangay field. As you can see the image bellow the field is still empty.

So, you

  • choose the province
  • the popup appears
  • you select the province
  • and automatically you would like to populate the Barangay and City fields?

Yes sir that`s correct. I was able to populate it but I am unable to choose city and province. when I am using this code below:

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
    $_REQUEST['request_data'] = $_REQUEST['city'];
}else{
    $parameters_advanced='`dvt3_city_id_c`="'. $_REQUEST['request_data'].'"';// example part of SQL WHERE
}


Error when clicking the result data

But if I used this code I can choose city and barangay. The only problem is, it has a bug the search is not working. If you click search and input the name value the result will be empty.

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
}else{
    $parameters_advanced='`dvt3_city_id_c`=" "'; // example part of SQL WHERE
}

And I wan`t also to retain the value also make it uneditable input field on the popupdef since it is my pre-filtered data

to populate the fields as you want them, you have to act on editviewdefs.

this code

if(!empty($_REQUEST['city'])){
    $parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
    $_REQUEST['request_data'] = $_REQUEST['city'];
}else{
    $parameters_advanced='`dvt3_city_id_c`="'. $_REQUEST['request_data'].'"';// example part of SQL WHERE
}

is for the initial popup filter, but if you want interdependent fields you need to open editviewdefs.php and find the field of interest (provinces) and enter something like this

 'displayParams' => 
            array (             
              'field_to_name_array' => 
              array (               
                'province_city' => 'city', //to the left the current field=>to the right the destination field            
                'id' => 'city_id',
              ),
            ),

@fab , so you mean I will change in the editview initial_filter?

From this:

'displayParams' => array(
                'initial_filter' => '&dvt2_province_id_c_advanced="+this.form.{$fields.dvt2_province_id_c.name}.value+"&custom_province_c_advanced="+this.form.{$fields.custom_province_c.name}.value+"',
              ),

To this:

'displayParams' => 
            array (             
              'field_to_name_array' => 
              array (               
                'province_city' => 'city', //to the left the current field=>to the right the destination field            
                'id' => 'city_id',
              ),
            ),

No, you have to add it:

'displayParams' => 
            array (       
              'initial_filter' => '&dvt2_province_id_c_advanced="+this.form.{$fields.dvt2_province_id_c.name}.value+"&custom_province_c_advanced="+this.form.{$fields.custom_province_c.name}.value+"',
              'field_to_name_array' => 
              array (               
                'province_city' => 'city', //to the left the current field=>to the right the destination field            
                'id' => 'city_id',
              ),
            ),

I am a little bit confuse on this

'province_city' => 'city', //to the left the current field=>to the right the destination field            
'id' => 'city_id',

province_city is the name of my province field and same to city?

province_city is the field name of the provinces module (the result of the choice with the arrow), within the Province module you will have a field named city (this is the field you will need to consider), city is the destination field, that is, the result of the popup (city of the Province module) will go to fill the city field of the current module (in your case, the Location module).

@fab , noted on this. Btw I have a question it is possible to set the pre-filtered field as readonly in popupdef and the clear button? Because I wan`t to exclude the pre-filtered field to be cleared once you clear the clear button.

Sorry, I don’t know how to make it readonly inside the popup, but by setting the initial filter in popudefs, even if you delete the field, it should remain unchanged

@fab , ow probably that is the best option if it is impossible to set the field as readonly, we can remove the field itself. Actually I need to make the field un-editable and it should be excluded on the clear button but if I am not mistaken it will have a lot of work to do in terms of modification.