From 479311a1cf361f3e352fd9d4dc4e027db353c1f4 Mon Sep 17 00:00:00 2001 From: Seamus Lee <seamuslee001@gmail.com> Date: Wed, 16 Oct 2019 22:52:17 +1100 Subject: [PATCH] Update custom data for apiv4 mentioning the class used for OOP coding format for Multi Record Custom data sets --- docs/api/v4/custom-data.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/api/v4/custom-data.md b/docs/api/v4/custom-data.md index e98e74f0..685f22fd 100644 --- a/docs/api/v4/custom-data.md +++ b/docs/api/v4/custom-data.md @@ -10,12 +10,32 @@ For setting custom date fields, date format is anything understood by `strtotime ## Multi-Record Custom Data -Multiple record custom data sets are treated by the API as entities, which work similarly to other entities attached to contacts (Phone, Email, Address, etc.). For example, creating a multi-record set named "Work_History" could then be accessed via the API as an entity named "Custom_Work_History". Creating a record would be done like so: +Multiple record custom data sets are treated by the API as entities, which work similarly to other entities attached to contacts (Phone, Email, Address, etc.). For example, creating a multi-record set named "Work_History" could then be accessed via the API as an entity named "Custom_Work_History" when accessing it via all forms except for in the PHP Object Oriented format, in that format the class you will be accessing is `CustomValue`. Creating a record would be done like so: + +Object Oriented format: +```php +$results = \Civi\Api4\CustomValue::create('Test_Multi_record_custom_fields') + ->addValue('entity_id', 202) + ->addValue('Test_Field', 555) + ->execute(); +``` + +Traditional: ```php civicrm_api4('Custom_Work_history', 'create', $params); ``` +```javascript +CRM.api4('Custom_Test_Multi_record_custom_fields', 'create', { + values: {"entity_id":202, "Test_Field":555} +}).then(function(results) { + // do something with results array +}, function(failure) { + // handle failure +}); +``` + ## Try It Out Once you have created some custom data in your system, look for it in the API explorer. Single-record data will appear as fields on the entities they extend, and multi-record data will appear in the list of entities (look under "C" alphabetically as they all start with the prefix "Custom_". -- GitLab