Changes

Line 371: Line 371:     
Note that this function is NOT recursive (it will fetch the records from the referenced table, and that's all, it won't fetch the custom fields of the referenced table nor recursively fetch the remote constrained custom fields). To do recursive fetching, see in the Facade API.
 
Note that this function is NOT recursive (it will fetch the records from the referenced table, and that's all, it won't fetch the custom fields of the referenced table nor recursively fetch the remote constrained custom fields). To do recursive fetching, see in the Facade API.
 +
 +
Note2: this function automatically manages Smart Value Substitution depending of the $field->column_name.
 +
 +
=== Recursive fetching referenced records of a constrained field ===
 +
 +
If you want to recursively fetch a constrained field (eg: constrainedfield1->ref_table->constrainedfield2->ref_table2->...), you need another function called fetchReferencedValuesRec(). Technically, this function is in the Facade API (inside /customfields/lib/customfields_aux.lib.php), but it isn't meant to be used by lambda users (contrary to customfields_fill_object()), but is mainly a helper function for the rest of the facade API.
 +
 +
fetchReferencedValuesRec() works very similarly to fetchReferencedValuesList(), but it will work recursively.
 +
 +
<source lang="php">
 +
$fkrecord = fetchReferencedValuesRec($customfields, $field, $id, $recursive=true)
 +
</source>
 +
 +
Where $customfields is the CustomFields instance for the module you are working on, $field is the constrained field you want to fetch, $id is the record's id you want to fetch, and $recursive enables or disables the recursion.
 +
 +
Note that this function automatically manages Smart Value Substitution (and also recursively).
 +
 +
Note2: This function tries to automatically avoid an infinite recursion loop by using a $blacklist: for a given constrained custom field, a table won't be visited twice. This means that for example you can do: invoice->user->socpeople->invoice, this will work and every referenced fields will be fetched, but it will automatically stop the recursion at the second invoice, because else it could continue in a loop to user, socpeople, invoice, user, socpeople, etc.
    
== Input forms for custom fields ==
 
== Input forms for custom fields ==
439

edits