Add third party address to intervention rows

Hello!
I’d like to ask some help on this problem, cause I’m a newbie on dolibarr. I’m trying to customize the rows of the interventions. I’ve added two complementary fields succesfully, but I’m having problem on a third one.

I need to add the address of the third party in the row of the intervention, and the other fields to (like date-time, duration).

So I added a complementary field filled by table values and I called it “sede cliente”. In the “value” attribute, if i set this:

socpeople:address:rowid::fk_soc=1

I get all the addresses I need from the record with ID = 1 of my third parties table, but if I change this to

socpeople:address:rowid::fk_soc=$ID$ the dropdown list remains empty.
What’s the correct syntax to get the list according to the third party I’m recording the intervention to?
Thank you!

Hello,

This is normal because the $ID$ is filled with the id of the object (intervention)

You should go for a calculated field with something like that (untested !) :

(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($objectoffield->socid) > 0)) ? $reloadedobj->address: ' '

Thanks ksar.
With your string I get this error:

Error in request SELECT rowid, ’ ’ FROM llx_(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($obj->socid) > 0)) ? $reloadedobj->address WHERE 1=1 ORDER BY ’ ’ You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($obj->soc…’ at line 1. Check setup of extra parameters.

Do you know if there is a guide for the syntax of extra parameters?
Thank you.

You need to change the extrafiled type, from " filled by table" by “calculated field”

But how can I choose between the addresses of the third party with a calculated field.
I need to get something like the image attached:

Hello,

In this case this is not possible with extrafields.
You need to go for external module développement

I don’t know if I explained it correcty, sorry…I created the field and I can see all the addresses of all third parties in the dropdown list. I just need to filter them by the id of the third party.
This is why, if I put the string
socpeople:address:rowid::fk_soc=1
I get them filtered by the third party with fk_soc=1, but I don’t know the syntax to sobstitute the “1” with the fk_soc I’m currently on.
Thanks.

You can use the following for your “filled by table” values

socpeople:address:rowid::fk_soc=($SEL$ s.rowid FROM llx_fichinterdet as fd
LEFT JOIN llx_fichinter as f ON fd.fk_fichinter = f.rowid
LEFT JOIN llx_societe as s ON f.fk_soc = s.rowid 
WHERE fd.rowid=$ID$
)

You may need to adapt the database prefix (llx_) to your installation.

Hello! Thanks, but the dropdown list of the addresses is still empty when I create a new line of the intervention details. It’s been billed when I modify a line that was saved before.

When you create a new line the sql-command for the complementary attributes field “filled from table” is executed.
In my example:

SELECT rowid as rowid, address FROM llx_socpeople WHERE fk_soc=(SELECT s.rowid FROM llx_fichinterdet as fd LEFT JOIN llx_fichinter as f ON fd.fk_fichinter = f.rowid LEFT JOIN llx_societe as s ON f.fk_soc = s.rowid WHERE fd.rowid=0 )

You see that the rowid of the new line is 0, because the line is not written to the db yet (0 means db-record is not written), the rowid will be changed (db-record is written) when you push the ADD button.
After that you can modify the line and the rowid is <> 0 and therefore the sql-command is executed now with the correct rowid

In my example:

SELECT rowid as rowid, address FROM llx_socpeople WHERE fk_soc=(SELECT s.rowid FROM llx_fichinterdet as fd LEFT JOIN llx_fichinter as f ON fd.fk_fichinter = f.rowid LEFT JOIN llx_societe as s ON f.fk_soc = s.rowid WHERE fd.rowid=7 )

So the working flow is as follows:

  1. create a new line
  2. push ADD button
  3. modify the line
  4. select the address from the list

Thanks DG-Rilling

I tried and it works. Modifying rows after saving will slow the filling of the intervention. Isn’t there any way to get the fk_soc ID of the intervention before saving a new intervention row?

There is a way, but the source code has to be changed.

Edit the file ~/htdocs/core/class/extrafields.class.php and search for:

public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '', $mode = 0)
	{

add $object to global, it looks like this

	global $conf, $langs, $form, $object;

then search for } elseif ($type == 'sellist') {
and scroll down to

	// current object id can be use into filter
	if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) {
		$InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]);
	} else {
		$InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
	}

Duplicate this block and exchange $ID$ in the duplicated block with $SOCADD$ and $objectid with $object->socid.

Then it look like this

	// current societe id can be use into filter
	if (strpos($InfoFieldList[4], '$SOCADD$') !== false && !empty($object->socid)) {
		$InfoFieldList[4] = str_replace('$SOCADD$', $object->socid, $InfoFieldList[4]);
	} else {
		$InfoFieldList[4] = str_replace('$SOCADD$', '0', $InfoFieldList[4]);
	}

Now you can use the complentary attribute field “select from table”

socpeople:address:rowid::fk_soc=$SOCADD$

It works! Thank you!