- Issue created by @aiden-grau
1. Problem
A webform designed to produce a new record for a custom field set (allowing multiple records) on a contact will create two records if one of the fields is a contact reference which references another contact that is newly created in the webform. The first record will have no value for the contact reference, and the other record will have ONLY the value for the contact reference.
2. Detailed steps to reproduce
Create a custom field set for contact entities that allows multiple records. In the field set include a contact reference field as well as other fields. Set up a webform that includes two civi contacts, enable the custom fields for Contact 1 and select Contact 2 as the contact to use for the contact reference. Contact 2 should be configured to make it possible to add an existing contact or create a new one. Make a submission in which you opt to create a new contact for Contact 2. You should find Contact 1 now has two new records for the custom field set, the first one missing a value for the contact reference, and the second containing only the contact reference value.
3. Proposed resolution
I wouldn't be so bold as to suggest one! The problem is that the custom field values are written when Contact 1 is created/updated, and after Contact 2 has been created saveContactRefs() of course writes that value separately. In my case I hacked the code for this occasion, when conditions are met I unset the custom fields before Contact 1 is created/updated and then use updateContact() instead of saveContactRefs() to save all the custom field values in the same call.
My guess is webform being used this way is rare and there's no great need for serious attention on this matter, but always good to report these things.
Active
5.7
CiviCRM Data Handling