<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dolibarr.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Shiquoza</id>
	<title>Dolibarr ERP CRM Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dolibarr.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Shiquoza"/>
	<link rel="alternate" type="text/html" href="https://wiki.dolibarr.org/index.php/Special:Contributions/Shiquoza"/>
	<updated>2026-11-25T06:36:35Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://wiki.dolibarr.org/index.php?title=Extrafields&amp;diff=68584</id>
		<title>Extrafields</title>
		<link rel="alternate" type="text/html" href="https://wiki.dolibarr.org/index.php?title=Extrafields&amp;diff=68584"/>
		<updated>2026-10-26T12:14:07Z</updated>

		<summary type="html">&lt;p&gt;Shiquoza: Document Object Link extrafield filter syntax (#37610)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!-- BEGIN origin interlang links --&amp;gt;&lt;br /&gt;
&amp;lt;!-- You can edit this section but do NOT remove these comments&lt;br /&gt;
     Links below will be automatically replicated on translated pages by PolyglotBot --&amp;gt;&lt;br /&gt;
[[zh:附加字段]]&lt;br /&gt;
[[fr:Champs_personnalises]]&lt;br /&gt;
&amp;lt;!-- END interlang links --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{TemplateDocDevEn}}&lt;br /&gt;
&lt;br /&gt;
=Extrafields=&lt;br /&gt;
Extrafields allow to add others datas to Dolibarr standard database schema. Introduced in version 3.2, extrafields are now implemented in most business objects&amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
*Thirdparties &amp;amp; contacts&lt;br /&gt;
*Users&lt;br /&gt;
*Events&lt;br /&gt;
*Proposal&lt;br /&gt;
*Customer Invoices&lt;br /&gt;
*Orders&lt;br /&gt;
*Supplier Proposal&lt;br /&gt;
*Supplier Invoices&lt;br /&gt;
*Supplier Orders&lt;br /&gt;
*Products &amp;amp; services&lt;br /&gt;
*Member &amp;amp; member type&lt;br /&gt;
*Projects &amp;amp; project tasks (since 3.4)&lt;br /&gt;
*Categories&lt;br /&gt;
*Expense Report&lt;br /&gt;
&lt;br /&gt;
=Technical implementation=&lt;br /&gt;
&lt;br /&gt;
Each object has its table in database to store values of extrafields.&lt;br /&gt;
&lt;br /&gt;
==Datatables extrafield tables models==&lt;br /&gt;
&lt;br /&gt;
  llx_&#039;&#039;BaseTableNAme&#039;&#039;_extrafields&lt;br /&gt;
  rowid                     integer AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;
  tms                       timestamp,&lt;br /&gt;
  fk_object                 integer NOT NULL,&lt;br /&gt;
  import_key                varchar(14)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example of mysql definition file for extrafields implementation on an object&amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;: &lt;br /&gt;
&lt;br /&gt;
  create table llx_place_room_extrafields&lt;br /&gt;
  (&lt;br /&gt;
    rowid                     integer AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;
    tms                       timestamp,&lt;br /&gt;
    fk_object                 integer NOT NULL,&lt;br /&gt;
    import_key                varchar(14)                          		-- import key&lt;br /&gt;
  ) ENGINE=innodb;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Unique&amp;quot; property of extrafield create a `UNIQUE INDEX` on this field, forcing objects to have a unique value for their extrafield (two objects cannot have the same value).&lt;br /&gt;
&lt;br /&gt;
=Usage=&lt;br /&gt;
&lt;br /&gt;
==Object Link filters==&lt;br /&gt;
&lt;br /&gt;
An Object Link extrafield can filter the objects shown in its selection list. The descriptor format is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
ObjectName:classPath:&amp;lt;showempty&amp;gt;:(field:operator:value)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to show objects whose status is 1:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
ObjectName:classPath:1:(status:=:1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The segments are:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ObjectName&amp;lt;/code&amp;gt;: the Dolibarr object name to link to.&lt;br /&gt;
* &amp;lt;code&amp;gt;classPath&amp;lt;/code&amp;gt;: the path to the PHP class for that object.&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;amp;lt;showempty&amp;amp;gt;&amp;lt;/code&amp;gt;: use 0 or 1 in this slot. Current code has a nuance: extrafield rendering derives whether to offer an empty choice from the field&#039;s Required and default-value settings, while the link-field parser treats a numeric third segment as its add-create-button flag. Do not rely on this slot to override the empty-choice setting.&lt;br /&gt;
* &amp;lt;code&amp;gt;(field:operator:value)&amp;lt;/code&amp;gt;: a filter in Dolibarr&#039;s Universal Filter Syntax. Keep it in parentheses, with the field name, operator, and value separated by colons.&lt;br /&gt;
&lt;br /&gt;
Supported operators are &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;!=&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;amp;lt;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;amp;gt;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;amp;lt;=&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;amp;gt;=&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;in&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;notin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;like&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;notlike&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;is&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;isnot&amp;lt;/code&amp;gt;. For example, &amp;lt;code&amp;gt;(status:=:1)&amp;lt;/code&amp;gt; means &amp;lt;code&amp;gt;status = 1&amp;lt;/code&amp;gt;. Criteria can be combined with &amp;lt;code&amp;gt;AND&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;OR&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Placeholders and object context===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;$ID$&amp;lt;/code&amp;gt; is the ID of the current object. For an extrafield on an invoice line, it is the line ID, not the parent invoice ID or its third party.&lt;br /&gt;
* &amp;lt;code&amp;gt;$MODE$&amp;lt;/code&amp;gt; is replaced with the current display mode, such as list or view.&lt;br /&gt;
* &amp;lt;code&amp;gt;$ENTITY$&amp;lt;/code&amp;gt; is replaced with the current entity ID.&lt;br /&gt;
* &amp;lt;code&amp;gt;$SEL$&amp;lt;/code&amp;gt; can represent &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; in a subquery only when the PHP global &amp;lt;code&amp;gt;$dolibarr_allow_unsecured_select_in_extrafields_filter&amp;lt;/code&amp;gt; is enabled. This permits unsecured SELECT subqueries and is disabled unless explicitly enabled. Enabling it is an administrator security decision; a subquery should not be presented as the default workaround.&lt;br /&gt;
&lt;br /&gt;
The issue&#039;s example, &amp;lt;code&amp;gt;Contact:contact/class/contact.class.php:*:fk_soc=:__THIRDPARTY_ID__&amp;lt;/code&amp;gt;, is malformed: the filter needs parentheses and the &amp;lt;code&amp;gt;field:operator:value&amp;lt;/code&amp;gt; format. A syntactically corrected form using the supported current-object placeholder is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
Contact:contact/class/contact.class.php:1:(fk_soc:=:$ID$)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On an invoice-line extrafield, however, &amp;lt;code&amp;gt;$ID$&amp;lt;/code&amp;gt; is the line ID, so this does not filter contacts by the parent invoice&#039;s third party. &amp;lt;code&amp;gt;__THIRDPARTY_ID__&amp;lt;/code&amp;gt; is a template substitution token, not a placeholder supported by this extrafield-filter path. The parent third party is not directly exposed to this filter.&lt;br /&gt;
&lt;br /&gt;
==Load class for extrafields==&lt;br /&gt;
To use extrafields all pages need include &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
require_once DOL_DOCUMENT_ROOT.&#039;/core/class/extrafields.class.php&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Load extrafield array in object==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$extrafields = new ExtraFields($db);&lt;br /&gt;
$extralabels=$extrafields-&amp;gt;fetch_name_optionals_label($object-&amp;gt;table_element);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
$extralabels will be an array with code and label of extrafields.&lt;br /&gt;
This code must be placed into the class for example into the function &amp;quot;write_file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Load extrafield into object==&lt;br /&gt;
&lt;br /&gt;
Extrafields are loaded in $object-&amp;gt;array_options array.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$object-&amp;gt;fetch($rowid);&lt;br /&gt;
$object-&amp;gt;fetch_optionals($rowid,$extralabels);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code must be placed just after the above.&lt;br /&gt;
&lt;br /&gt;
==Display extrafield value into PDF or HTML==&lt;br /&gt;
After load extrafields&lt;br /&gt;
&lt;br /&gt;
HTML Exemple&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
print $object-&amp;gt;array_options [&#039;options_XXX&#039;];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Where XXX is the code of the extrafields&lt;br /&gt;
&lt;br /&gt;
PDF example&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$pdf-&amp;gt;MultiCell (0,5, $outputlangs-&amp;gt;convToOutputCharset($object-&amp;gt;array_options [&#039;options_XXX&#039;]),0,&#039;L&#039;); )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Where XXX is the code of the extrafields&lt;br /&gt;
&lt;br /&gt;
A dedicated page to show how to integrate extrafileds into PDF can be found there&amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;: [[Add Extrafields on PDF Models]]&lt;br /&gt;
&lt;br /&gt;
==Display extrafield value of lines into PDF or HTML==&lt;br /&gt;
After load extrafields&lt;br /&gt;
&lt;br /&gt;
HTML Exemple&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
print $object-&amp;gt;lines[$i]-&amp;gt;array_options[&#039;options_XXX&#039;];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Where XXX is the code of the extrafields&lt;br /&gt;
&lt;br /&gt;
PDF example&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$pdf-&amp;gt;MultiCell (0,5, $outputlangs-&amp;gt;convToOutputCharset($object-&amp;gt;lines[$i]-&amp;gt;array_options[&#039;options_XXX&#039;]),0,&#039;L&#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Where XXX is the code of the extrafields&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How to change the labels of the columns when using models (propals, etc.)==&lt;br /&gt;
In the PHP code of the model you can change the labels of your extrafield by changing into the function named &amp;quot;_tableau(...)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Before call $object-&amp;gt;create() or $object-&amp;gt;update()==&lt;br /&gt;
&lt;br /&gt;
Values of extrafields sent by form need to be retrieve. For doing that, use this method&amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$ret = $extrafields-&amp;gt;setOptionalsFromPost($extralabels,$object);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Inside edit page to display extrafields==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$reshook=$hookmanager-&amp;gt;executeHooks(&#039;formObjectOptions&#039;,$parameters,$object,$action);    // Note that $action and $object may have been modified by hook&lt;br /&gt;
if (empty($reshook) &amp;amp;&amp;amp; ! empty($extrafields-&amp;gt;attribute_label))&lt;br /&gt;
{&lt;br /&gt;
      print $object-&amp;gt;showOptionals($extrafields,&#039;edit&#039;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Inside view page to display extrafields==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$reshook=$hookmanager-&amp;gt;executeHooks(&#039;formObjectOptions&#039;,$parameters,$object,$action);    // Note that $action and $object may have been modified by hook&lt;br /&gt;
if (empty($reshook) &amp;amp;&amp;amp; ! empty($extrafields-&amp;gt;attribute_label))&lt;br /&gt;
{&lt;br /&gt;
      print $object-&amp;gt;showOptionals($extrafields);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==After fetch method of this object class==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
require_once(DOL_DOCUMENT_ROOT.&#039;/core/class/extrafields.class.php&#039;);&lt;br /&gt;
$extrafields=new ExtraFields($this-&amp;gt;db);&lt;br /&gt;
$extralabels=$extrafields-&amp;gt;fetch_name_optionals_label($this-&amp;gt;table_element,true);&lt;br /&gt;
if (count($extralabels)&amp;gt;0) {&lt;br /&gt;
	$this-&amp;gt;fetch_optionals($this-&amp;gt;id,$extralabels);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==After Update method of this object class&amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;:==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// Actions on extra fields (by external module or standard code)&lt;br /&gt;
// FIXME le hook fait double emploi avec le trigger !!&lt;br /&gt;
$hookmanager-&amp;gt;initHooks(array(&#039;HookModuleNamedao&#039;));&lt;br /&gt;
$parameters=array(&#039;socid&#039;=&amp;gt;$this-&amp;gt;id);&lt;br /&gt;
$reshook=$hookmanager-&amp;gt;executeHooks(&#039;insertExtraFields&#039;,$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks&lt;br /&gt;
if (empty($reshook))&lt;br /&gt;
{&lt;br /&gt;
	if (empty($conf-&amp;gt;global-&amp;gt;MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used&lt;br /&gt;
	{&lt;br /&gt;
            $result=$this-&amp;gt;insertExtraFields();&lt;br /&gt;
            if ($result &amp;lt; 0)&lt;br /&gt;
            {&lt;br /&gt;
            	$error++;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
else if ($reshook &amp;lt; 0) $error++;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==After delete method of this object class==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
// Removed extrafields&lt;br /&gt;
if (! $error)&lt;br /&gt;
{&lt;br /&gt;
      if (empty($conf-&amp;gt;global-&amp;gt;MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used&lt;br /&gt;
      {&lt;br /&gt;
      $result=$this-&amp;gt;deleteExtraFields();&lt;br /&gt;
      if ($result &amp;lt; 0)&lt;br /&gt;
      {&lt;br /&gt;
        $error++;&lt;br /&gt;
        dol_syslog(get_class($this).&amp;quot;::delete erreur &amp;quot;.$errorflag.&amp;quot; &amp;quot;.$this-&amp;gt;error, LOG_ERR);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Admin pages==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$elementtype=&#039;facture&#039;; //Must be the $table_element of the class that manage extrafield&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Repair Database=&lt;br /&gt;
Search and find definition of $listofmodulesextra add the new extrafield declaration&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;PHP&amp;quot;&amp;gt;&lt;br /&gt;
$listofmodulesextra=array(&#039;societe&#039;=&amp;gt;&#039;societe&#039;,&#039;adherent&#039;=&amp;gt;&#039;adherent&#039;,&#039;product&#039;=&amp;gt;&#039;product&#039;,&lt;br /&gt;
			&#039;socpeople&#039;=&amp;gt;&#039;socpeople&#039;, &#039;commande&#039;=&amp;gt;&#039;commande&#039;, &#039;facture&#039;=&amp;gt;&#039;facture&#039;,&lt;br /&gt;
			&#039;commande_fournisseur&#039;=&amp;gt;&#039;commande_fournisseur&#039;, &#039;actioncomm&#039;=&amp;gt;&#039;actioncomm&#039;,&lt;br /&gt;
			&#039;adherent_type&#039;=&amp;gt;&#039;adherent_type&#039;,&#039;user&#039;=&amp;gt;&#039;user&#039;,&#039;projet&#039;=&amp;gt;&#039;projet&#039;, &#039;projet_task&#039;=&amp;gt;&#039;projet_task&#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Related videos=&lt;br /&gt;
&lt;br /&gt;
Extrafields:&lt;br /&gt;
(vocal in french but subtitles are available and review in this language)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;youtube width=&amp;quot;200&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;Eex2YXxToS0&amp;lt;/youtube&amp;gt; &lt;br /&gt;
&amp;lt;youtube width=&amp;quot;200&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;QQnyoUGsN1c&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&amp;lt;youtube width=&amp;quot;200&amp;quot; height=&amp;quot;180&amp;quot;&amp;gt;md6JHbd8o_0&amp;lt;/youtube&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shiquoza</name></author>
	</entry>
</feed>