How to set ExtraFields durring trigger execution

Hi Forum,

I just started working with triggers and now I’m facing an issue with setting the values for an object.
Is it possible to set values for ExtraFields which have been configured in a module?
In my case I added a field for an uid of a external system. Once a project is created I would like to create the project in the external system as well and link them by the uid.

I tried to set the external field by using this lines:

case 'PROJECT_CREATE':
    dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
    $projectId = $this->createExternalProject($object);
    $object->array_options['options_uid'] = $projectId;
    break;

This does’t work. Probably I need to use a function which I’m not aware of?
Can anybody help with this?

Thank you and best regards
Phillip

Hi,

Difficult to help with this little information.
What does mean “it doesn’t work” ?

Hi,

once the trigger is executed and returns an ok value ($ok = 0;) the ExtraField with the name uid is empty.
In the meantime I found a function which might work $object->updateExtraField() but I’m still working on this.

Thank you an best regards
Phillip

Thanks for your help.
I just found the solution:

$object->array_options['options_uid'] = $uid;
$object->updateExtraField('uid', '');

This updates the ExtraFields of the object.

3 Likes