Answers.Body: <p>I was able to resolve this by running a related search using Search Kit. I was able to use this to produce a search that listed the relationship ID, the name and contact ID's of the individual and organisation in the 'employee of' and 'employer' relationship respectively. I then exported this and imported it back as part of a 'relationship' update, mapping the organisation contact ID to the 'Is current employer?' field. This updated the Primary employer field for each individual and this showed in the 'Employer' field in the Cotnact Summary page for the individual too.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-20T09:31:35.027Z
Answers.LastActivityDate: 2024-11-20T09:31:35.027Z
Answers.UserDisplayName: Jamie
Answers.Body: <p>I did this before</p>
  <pre><code>cv api4 Relationship.update '{&quot;values&quot;:{&quot;is_active&quot;:1,&quot;is_current_employer&quot;:1},&quot;where&quot;:[[&quot;contact_id_a.employer_id&quot;,&quot;IS EMPTY&quot;],[&quot;is_active&quot;,&quot;=&quot;,1],[&quot;relationship_type_id&quot;,&quot;=&quot;,5]]}’
  </code></pre>
  <p>I guess you can do it from UI api4 explorer</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-20T09:34:20.117Z
Answers.Text: Thanks for the suggestion Pradeep. This isn't possible directly through API4 - at least not on my install, as "is_current_employer"just isn't an available option but eventually I was able to take a similar approach to your suggestion by way of Search Kit. Thanks
Answers.UserDisplayName: Jamie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-12T16:14:37.637Z
Answers.LastActivityDate: 2024-11-12T16:14:37.637Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I have just over 100 individual contacts (Contact A) in my database that have an identified employer (contact B) relationship that has a start date in the past and no end date. However, only a small number had an identified 'Primary Employer'. I followed the suggested approach here <a href="https://civicrm.stackexchange.com/questions/31289/how-can-i-bulk-update-the-contact-employer-based-on-the-employee-relationship">How can I bulk update the contact employer based on the employee relationship?</a> using the API4 to make all of these active. This did make the relationships 'active' but it didn't make the identity of Contact become the 'Primary Employer' - in fact it removed the record of the 'Primary Employer' from the small number that had theirs in place. I also found this question and answer <a href="https://civicrm.stackexchange.com/questions/31289/how-can-i-bulk-update-the-contact-employer-based-on-the-employee-relationship">How can I bulk update the contact employer based on the employee relationship?</a> which seems to hit the mark except that the solution requires the running of a query directly on the database which I don't have access to as it's a hosted SAAS solution.</p>
  <p>Is there any alternative that can achieve either through the API4 or some other way that doesn't require me to run a query on the database?</p>
  <p>Any help greatly appreciated.</p>
  
Tags: <relationships><batches><api4>
Title: How do I batch update 'primary employer' in line with the identity of Employer (Contact B)?
ThreadText: # How do I batch update 'primary employer' in line with the identity of Employer (Contact B)?
  
  (Asked by: username_0 on 2024-11-12)
  
  I have just over 100 individual contacts (Contact A) in my database that have an identified employer (contact B) relationship that has a start date in the past and no end date. However, only a small number had an identified 'Primary Employer'. I followed the suggested approach here [How can I bulk update the contact employer based on the employee relationship?](https://civicrm.stackexchange.com/questions/31289/how-can-i-bulk-update-the-contact-employer-based-on-the-employee-relationship) using the API4 to make all of these active. This did make the relationships 'active' but it didn't make the identity of Contact become the 'Primary Employer' - in fact it removed the record of the 'Primary Employer' from the small number that had theirs in place. I also found this question and answer [How can I bulk update the contact employer based on the employee relationship?](https://civicrm.stackexchange.com/questions/31289/how-can-i-bulk-update-the-contact-employer-based-on-the-employee-relationship) which seems to hit the mark except that the solution requires the running of a query directly on the database which I don't have access to as it's a hosted SAAS solution.
  
  Is there any alternative that can achieve either through the API4 or some other way that doesn't require me to run a query on the database?
  
  Any help greatly appreciated.
  
  **Tags:** relationships, batches, api4
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2024-11-20. Score: 2
  
  I was able to resolve this by running a related search using Search Kit. I was able to use this to produce a search that listed the relationship ID, the name and contact ID's of the individual and organisation in the 'employee of' and 'employer' relationship respectively. I then exported this and imported it back as part of a 'relationship' update, mapping the organisation contact ID to the 'Is current employer?' field. This updated the Primary employer field for each individual and this showed in the 'Employer' field in the Cotnact Summary page for the individual too.
  
  
  ---
  
  ### Answer by username_1 on 2024-11-12. Score: 0
  
  I did this before
  
  ```
  cv api4 Relationship.update '{"values":{"is_active":1,"is_current_employer":1},"where":[["contact_id_a.employer_id","IS EMPTY"],["is_active","=",1],["relationship_type_id","=",5]]}’
  
  ```
  
  I guess you can do it from UI api4 explorer
  
  > **Comments:**
  > **username_0**: Thanks for the suggestion username_1. This isn't possible directly through API4 - at least not on my install, as "is_current_employer"just isn't an available option but eventually I was able to take a similar approach to your suggestion by way of Search Kit. Thanks  
  
  ---
  
  