Answers.Body: <p>We ended up using Markup field in the webform with some PHP code that made a CiviCRM API call:</p>
  
  <pre><code>&lt;?php
  $params = array(
    'version' =&gt; 3,
    'is_active' =&gt; 1,
    'sequential' =&gt; 1,
    'contact_id_a' =&gt; $_SESSION['CiviCRM']['contact_id'],
    'relationship_type_id' =&gt; 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 ) { ?&gt;
      &lt;input onclick="location.href='/link-to-webform?cid1=&lt;?php echo $employer_id ?&gt;';" type="button" value="Manage Contacts" /&gt;
  &lt;?php }
  </code></pre>
  
  <p>I'm going to file an issue on the module.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-09T20:14:52.133Z
Answers.Text: That's very cool!
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-15T07:42:49.403Z
Answers.Text: This will only be correct if there is only 1 employer. If there are multiple employers this will give rather randomly the one that sequential finds first.
Answers.UserDisplayName: Hans Rossel
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-09T19:45:18.033Z
Answers.LastActivityDate: 2016-05-17T13:21:14.553Z
Answers.LastEditDate: 2016-05-17T13:21:14.553Z
Answers.UserDisplayName: Dan O'Brien
Body: <p>I'm trying to create a link to a CiviCRM-integrated Drupal webform that passes the ID of a contact's employer</p>
  
  <p>I'm trying to use</p>
  
  <p><a href="http://somedomain.org/node/9999?cid1=[current-user:civicrm-contact:employer-id]" rel="nofollow">http://somedomain.org/node/9999?cid1=[current-user:civicrm-contact:employer-id]</a></p>
  
  <p>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 <em>name</em> of the current employer.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-07T18:04:50.480Z
Comments.Text: Gosh I didn't even know tokens like that existed. What module is generating them?
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-08T00:07:04.190Z
Comments.Text: 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?
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-09T19:39:04.260Z
Comments.Text: The CiviCRM Entity module is where those tokens come from.
  https://www.drupal.org/project/civicrm_entity
Comments.UserDisplayName: Dan O'Brien
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-04T18:16:42.347Z
Comments.Text: Also, I'm trying to use the token to CREATE the value for cid1=
Comments.UserDisplayName: Dan O'Brien
Tags: <webform-civicrm><civicrm-entity>
Title: Can I reference the contact ID of the Current Employer with a Drupal entity token?
ThreadText: # Can I reference the contact ID of the Current Employer with a Drupal entity token?
  
  (Asked by: username_0 on 2016-05-02)
  
  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.
  
  **Tags:** webform-civicrm, civicrm-entity
  
  > **Comments:**
  > **username_1**: Gosh I didn't even know tokens like that existed. What module is generating them?  
  > **username_2**: 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?  
  > **username_0**: The CiviCRM Entity module is where those tokens come from. https://www.drupal.org/project/civicrm_entity  
  > **username_0**: Also, I'm trying to use the token to CREATE the value for cid1=  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-05-09. Score: 3 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_3**: That's very cool!  
  > **username_4**: This will only be correct if there is only 1 employer. If there are multiple employers this will give rather randomly the one that sequential finds first.  
  
  ---
  
  