Adding addCondition() in a Form with fields from other tables

ms access if statement with two conditions
magento 2 custom rule condition
cdbcriteria
servicenow add condition builder to form
access calculated field from another table
servicenow add dot walked field to form
cdbcriteria group by
access query criteria based on another field

I don't know the syntax to access "CurrentTable.ForeignKey" nor "OtherTable.PrimaryKey" in a $model->addCondition() statement.

This is a fragment of my code which works: $mm = new SYSPC_MODEL($this->app->db,['title_field'=>'MODEL_NAME']); $mm->addCondition('MODEL_NAME', 'LIKE', 'DESK%');

In place of simply searching for MODEL_NAME like 'DESK%', I would like to display only the FK_MODEL_id values which exist in the SYSPC_MODEL table for the same FK_OS_ID than the current record FK_OS_ID value. So in SQL, we should have something like: SELECT SYSPC_MODEL.MODEL_NAME WHERE ( DHCP_PC.FK_OS_ID = SYSPC_MODEL.id )

To understand easier the context, I reduced my code as much as possible:

<?php
include_once ('../include/config.php');
require '../vendor/autoload.php';

class SYSPC_OS  extends \atk4\data\Model {
    public $table = 'SYSPC_OS';
    function init() {
        parent::init();
        $this->addFields([ ['OS_NAME',         'required'=>true, 'caption'=>'Identifiant d\'OS'],
                            ['OS_DESCRIPTION', 'required'=>true, 'caption'=>'Description d\'OS']
                        ]);
    }
}     // End of class SYSPC_OS

class SYSPC_MODEL  extends \atk4\data\Model {
    public $table = 'SYSPC_MODEL';
    function init() {
        parent::init();
        $this->addFields([ ['MODEL_NAME',     'caption'=>'Nom du modele'],
                            ['MODEL_BASE_RPM', 'caption'=>'Rpm de base']
                        ]);
        $this->hasOne('FK_OS_id',[new SYSPC_OS(),'ui'=>['visible'=>false]])->addField('OS_NAME','OS_NAME');
    }
}     // End of class SYSPC_MODEL

class DHCP_PC  extends \atk4\data\Model {
    public $table = 'DHCP_PC';
    function init() {
        parent::init();
        $this->addFields([  ['PCNAME',      'required'=>true, 'caption'=>'Nom du pc']
                        ]);
        $this->hasOne('FK_OS_ID',['required'=>true,new SYSPC_OS(),'ui'=>['visible'=>false]])->addField('OS_NAME','OS_NAME');
        $this->setOrder('PCNAME','asc');
        $this->hasOne('FK_MODEL_id',['required'=>true,new SYSPC_MODEL(),'ui'=>['visible'=>false]])->addField('MODEL_NAME','MODEL_NAME');
    }
}      // End of class DHCP_PC

class PcForm extends \atk4\ui\Form {
    function setModel($m, $fields = null) {
        $PcWidth = 'three';
        parent::setModel($m, false);
        $gr = $this->addGroup('PC name');
        $gr->addField('PCNAME',['required'=>true,'caption'=>'Nom du pc']);
        $gr = $this->addGroup('OS');
        $mm2 = new SYSPC_OS($this->app->db,['title_field'=>'OS_NAME']);
        $gr->addField('FK_OS_ID',['width'=>$PcWidth],['DropDown'])->setModel($mm2);

        $gr = $this->addGroup('Modèle');
        $mm = new SYSPC_MODEL($this->app->db,['title_field'=>'MODEL_NAME']);
        $mm->addCondition('MODEL_NAME', 'LIKE', 'DESK%');  // Works fine but I would like to display only the FK_MODEL_id values 
                                                            // which exist in the SYSPC_MODEL table for the same FK_OS_ID 
                                                            // than the current record FK_OS_ID value :
                                                            // SELECT SYSPC_MODEL.MODEL_NAME WHERE ( DHCP_PC.FK_OS_ID = SYSPC_MODEL.id )
        $gr->addField('FK_MODEL_id', ['width'=>$PcWidth], ['DropDown'])->setModel($mm);
        return $this->model;
    }
}     // End of class PcForm

$app = new \atk4\ui\App();
$app->title = 'Gestion des PC';
$app->initLayout($app->stickyGET('layout') ?: 'Admin');
$app->db = new \atk4\data\Persistence_SQL(
    "pgsql:host=".$GLOBALS['dbhost'].";dbname=".$GLOBALS['dbname'],
    $GLOBALS['dbuser'],
    $GLOBALS['dbpass']
);
$g = $app->add(['CRUD', 'formDefault'=>new PcForm()]);
$g->setIpp([10, 25, 50, 100]);
$g->setModel(new DHCP_PC($app->db),['PCNAME', 'OS_NAME', 'MODEL_NAME']);
?>

Please look at https://github.com/atk4/ui/pull/551 - it might be what you're looking for.

Example here: https://ui.agiletoolkit.org/demos/autocomplete.php

Docs: https://agile-ui.readthedocs.io/en/latest/autocomplete.html?highlight=lookup#lookup-field

$form = $app->add(new \atk4\ui\Form(['segment']));
$form->add(['Label', 'Add city', 'top attached'], 'AboveFields');

$l = $form->addField('city',['Lookup']);

// will restraint possible city value in droddown base on country and/or language.
$l->addFilter('country', 'Country');
$l->addFilter('language', 'Lang');

//make sure country and language belong to your model.
$l->setModel(new City($db));

Magento Add Condition Rule In A Custom Form in magento 2 , To add a conditional field to the default model (and further utilize it for <?php namespace Vendor\Rules\Setup; use Magento\Framework\DB\Ddl\Table; use int|null getRuleId() * @method Rule setRuleId(int $id) */ class Rule extends ' style' => 'height: 100px;' ] ); $fieldset->addField( 'is_active', 'select',� What possibly be the best way to add fields from another tables on a form? 1. Flowfield? 2. Or declaring a variable and assigning the value by writing code on onaftergetrecord trigger via GET function? Does flowfield affects the database performance? *Need to just display the information*

Alternatively you can use something other than drop-down, here is UI example:

https://ui.agiletoolkit.org/demos/multitable.php

Selecting value in the first column narrows down options in the next. You can have a hidden field inside your form where you can put the final value.

Create conditional (Boolean) expressions - Access, Conditional expressions take the same form and use the same basic syntax as and you can use them in the same ways that you use other expressions: For table fields, you add your expression to the Validation Rule property of the field. Using an expression such as Date() in the Control Source property displays the� The Add Condition button from the User Form will add another set of controls, to set a new condition for filtering the table. Important note: The VBA code for applying filters is very basic, just for demo purposes, that is, you cannot apply more than 1 criteria for the same column.

Thanks for your support but I still have some questions. Question 1: I found "addRelatedEntity" and "relEntity" but I didn't found a description of those commands. Does it exist ? Is this a possible solution for my issue ? Question 2: Is it possible to 'Lookup' in another table and if yes, how ? Question 3: If 'Lookup' is not the solution, how to make a join (with filtering in the where clause) inside a model ? Question 4: If the join is not the solution, is it possible to use DSQL inside a model ? Question 5: Or do you have a DSQL example (with a self made join between several tables) associated with a CRUD ?

Create a condition statement using the condition builder , For example, in the Incident [incident] table, the Active field offers a choice list with Note: The condition builder in the list filter has a different appearance in List v2 and List v3. In UI16, condition builders in forms can be configured to look and work like To add a dependent condition, click AND or OR next to the condition. Add, configure, move, or delete fields on a form. 05/04/2020; 8 minutes to read; In this article. Add, configure, move, or delete fields using the form designer. Add fields to a form. To add fields to a form, use the Fields pane. The Fields pane lets you search and filter to help you quickly find fields. It also includes the option to show only

CDbCriteria | API Documentation for Yii 1.1, system.web.form __wakeup(), Remaps criteria parameters on unserialize to prevent name collisions. If this is set true, the SELECT clause would be changed to SELECT DISTINCT. $columns, array, list of column names and values to be matched public static addCondition(mixed $condition, string $ operator='AND'). You can quickly add fields to a form or report by using the Field List pane. When you double-click a field in the Field List pane (or if you drag a field from the list to your form or report), Microsoft Access automatically creates the appropriate control to display the field — for example, a text box or check box — and then binds the control to that field.

How to Add Conditions to Fields in WordPress Form , For this purpose, add condition 2. Click “Add” to insert another condition. Select “ Parents Residing in Canada” from the first drop-down. In both� A third table is called "Department Managers" and is the same as the above two tables. A fourth table is called "People" and consists of general employees and their contact details. This table has ten fields, seven of which are popoulated with the data related to employees.

Use Queries to show records based on conditions, 1, select, Selects which columns to return, and in what order. of submitted form responses or; have issues with other Google Sheets add-ons. and will always reference the current date since it uses the today() function. If, after creating your form, you realize that you want to add a field to your form that doesn't yet exist in your table, you can click the + Add a field to this table button in the Fields sidebar. Additionally, you can customize your fields' settings by clicking on a field, clicking the dropdown arrow next to the name of the field, and

Comments
  • The example is extremely complex, so I couldn't fully understand it but my guess is that you want selected value of first field to limit number of options in another field. I'll try to find example.
  • You are completly right: I try to set in ATK a SQL statement like: SELECT SYSPC_MODEL.MODEL_NAME WHERE ( DHCP_PC.FK_OS_ID = SYSPC_MODEL.id ) I searched in the doc and I found "addRelatedEntity" and "relEntity" but I didn't found a description of those commands.
  • I searched and I found "addRelatedEntity" and "relEntity" but I didn't found a description of those commands. Does it exist ? Please tell me if I'm on the right path or if I can specify a field from another table in a "addCondition" statement. Thanks for your help
  • Your question were good. Did you ever make it work? Your followup questions were good too, too bad you posted them as an answer instead of a comment to the actual answers. So, probably noone has ever seen them.
  • @Marki : Thanks for the info.