2

I want to rename the column/fields I am retreiving in the SELECT statement. Best way to ask this is by showing an example...

Given this select call:

$contacts = civicrm_api4('Contact', 'get', [
  'select' => [ 'id', 'display_name', ],
  'limit' => 5,
  'checkPermissions' => TRUE,
]);

Which returns object with:

[{"id": 2983,"display_name": null },]

But what if I want to rename the 'display_name' field as something else (say 'dname'), to get a result like this:

[{"id": 2983,"dname": null },]

I tried both the following but it does not work:

  'select' => [ 'id', 'display_name AS dname', ],
  'select' => [ 'id', 'display_name as dname', ],

Is there a way to do this, or is it not possible with the API call?

Thanks

1 Answer 1

3

There was a long discussion about this at https://lab.civicrm.org/dev/core/-/issues/3738

which resulted in a new $result->rekey() method added to the next beta (5.74).

See https://github.com/civicrm/civicrm-core/pull/29714

1
  • Okay so that at least answers my question: "No you can not do that (yet)"!
    – jsherk
    Apr 20 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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