4

I'm looking to print / email groups of contacts with a list of their accreditations which we've stored in a custom field set with multiple records. How do we get that to appear on emails & printouts? There is no option on the tokens dropdown.

We want the list to appear in a table format, showing all the entries.

Similar to this support post: http://forum.civicrm.org/index.php?topic=30029.0 / I found this post hard to find an answer from.

Any specific ideas? Thanks very much in advance!

  • OK; so our developer made a custom civicrm extension for us for these tokens. – IT Support Shanti Mission May 28 '15 at 7:34
3

You will need to create a custom token for this. Hook_civicrm_tokens is where you assign names to your tokens, and hook_civicrm_tokenValues is where you define the business logic. You will use the API to retrieve the custom field values for each contact, and loop through those values to build your HTML table. Below is an example of the basic API call, for contact 465 to return all the entries for Custom Field 12. Using CustomValue API is a bit different from the others as you'll see from the return.fieldname => 1 bit:

$result = civicrm_api3('CustomValue', 'get', array(
  'sequential' => 1,
  'entity_id' => 465,
  'entity_type' => "Contact",
  'return.custom_12' => 1,
));

This is a sample of the result:

{
    "is_error": 0,
    "version": 3,
    "count": 1,
    "id": 12,
    "values": [
        {
            "entity_id": "465",
            "latest": "Hope",
            "id": "12",
            "1": "Life",
            "2": "Hope"
        }
    ]
}
  • OK guys; thanks for your help; this coding is a bit too high level for me; will work with someone who knows more about this to configure our particular field sets. Regards, Peter – IT Support Shanti Mission May 28 '15 at 7:42
1

Tokens do not easily lend themselves to printing out multiple records, since this generally requires extra markup in the output to look the way you want (e.g. an ordered list or a table). However, with a little bit of custom code you could do it.

See Create Your Own Tokens for Fun and Profit for a how-to guide.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.