Update a field based on another in all records of a module

Ok so I have successfully created a before_save hook on the contacts module to update 2 custom fields from birthdate. Custom fields are ‘dob_month’ and ‘dob_day’. I use these for reports etc.

All works fine.

However I have several thousand records in contacts, so I don’t want to go through and save each contact to trigger the update. I’m a bit stumped as to how best to go about this and would appreciate some help to get me on the way.

I assume some kind of function to loop through each contact.

Thanks in advance.
Using SuiteCRM 7.13

you could add a scheduled job. they aren’t triggered by events, but by a pre-set schedule. When your method is invoked, you load the first 50 contacts without a birthday and initiate the save(), as soon as no contacts are left, you can disable the job or reduce its frequency.

Option b is a manual one: have you tried to go to the contacts ListView, select the whole page (or even all records) and do a mass-update on them (depending on your hook, this could take a while)?

Another option is a “All records” workflow. Make sure it runs only once.

Have some action set a dummy field. This will cause the record to save, and will trigger the hook.

It will take a long time to run, and use up many resources, so do it outside office hours.

Thanks pgr, that did the trick nicely.
I coded a function to run from the scheduler, but for some reason it just refused to run. Given that I should never need to do this again, your solution was muh easier.


1 Like