logic hooks - how do I create a new related record when saving?

Hi all,

I’m fairly new to SuiteCRM and php (historically working with VB / VB.NET / C#.NET …

When a user creates a new record in my custom module I want to be able to create a new related record, save it and link it via the relationship to the record being created.

I’ve tried using the bean factory, however, things seem to fall apart when I call the save() method. Currently, I’m trying to achieve this using the before_save logic hook. However, I can’t seem to get things to work. The examples I’ve found either want to link existing records, don’t work or link to documentation which has been relocated.

I’d be grateful if someone could push me in the right direction.

Many Thanks
GsyUser

1 Like

Turns out the main problem I was having was trying to create the record in the before_save hook, while the record I was creating also had a before_save hook.
Moving it to the ‘process_record’ hook seems to be working fine now.

Can you elaborate on this?

Which part of your code in which module did you move to ‘process_record’ hook?

How do you both create a new record and then further manipulate this new record as part of one logic_hook action? I can see how to add a new related record (with an unknown ID). But since the ID is unknown at runtime, how do I then manipulate that specific new related record?