3

I'm trying to create a link to a CiviCRM-integrated Drupal webform that passes the ID of a contact's employer

I'm trying to use

http://somedomain.org/node/9999?cid1=[current-user:civicrm-contact:employer-id]

but the token replacement is blank. [current-user:civicrm-contact:employer-id] also does not work. However, [current-user:civicrm-contact:current-employer] does replace with the name of the current employer.

  • Gosh I didn't even know tokens like that existed. What module is generating them? – Coleman May 7 '16 at 18:04
  • and this can't be done without tokens by putting the Contact's ID in the url and setting cid2 to be filtered based on the relationship? – petednz - fuzion May 8 '16 at 0:07
  • 1
    The CiviCRM Entity module is where those tokens come from. drupal.org/project/civicrm_entity – Dan O'Brien May 9 '16 at 19:39
  • Also, I'm trying to use the token to CREATE the value for cid1= – Dan O'Brien Jun 4 '16 at 18:16
2

We ended up using Markup field in the webform with some PHP code that made a CiviCRM API call:

<?php
$params = array(
  'version' => 3,
  'is_active' => 1,
  'sequential' => 1,
  'contact_id_a' => $_SESSION['CiviCRM']['contact_id'],
  'relationship_type_id' => 4,  // Employee Of
);
$result = civicrm_api('Relationship', 'get', $params);

if ( ! $result['is_error'] ) {
  $employer_id = array_shift($result['values'])['contact_id_b'];
}

if ( $employer_id ) { ?>
    <input onclick="location.href='/link-to-webform?cid1=<?php echo $employer_id ?>';" type="button" value="Manage Contacts" />
<?php }

I'm going to file an issue on the module.

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.