System User ID is not stored in new Notes

Hi gents

I’d like to create a new note useing “BeanFactory::newBean(‘Notes’);”. So far it works perfect. Since it is a system generated note, I’d like to save the System User (Administrator with ID 1) in the field “created_by” and “modified_user_id”, but what ever I try, it’s always NULL in the DB.

Here the code sniped:

// get system user for creating notes
$systemUser = BeanFactory::getBean('Users', 1);

// create a note to the contact
$note = newNote('Contacts', $delegate_id);
$note->name = 'blabla';
$note->description = 'blabla';
$note->modified_user_id = $systemUser->id;
$note->created_by = $systemUser->id;
$note->contact_id = $delegate_id;
$note->save();

I also tried it directly with “$note->created_by = ‘1’”. But no luck.

I am using SuiteCRM 8.7.1 in PROD and 8.8-beta in DEV with PHP 8.1.31.

Any ideas what I am doing wrong?

Thanks for your help.
Carsten

There are extra checks it does for setting the created by/ modified by

So try setting the following in addition to what you have

$note->set_created_by = false;
$note->update_modified_by = false;

Works like a char! :slight_smile: Thank you @Daman

I think you should upgrade your dev to v8.8 :face_with_peeking_eye: :smile:

Done! Also PROD is now on 8.8. :smiley: