Remove tags from multiple contacts

We would like to be able to quickly remove a tag from a group of contacts. Does anybody have any ideas how you can do this? We tried with the mass update, but there is unfortunately no possibility to remove data.

  • Hi Jan Frederic Buss,

    Since Tags is a separate module and not a field in the Contacts module, it represents a many-to-many (M-M) relationship. This means one tag can be associated with multiple contacts, and one contact can have multiple tags.

    If you find it challenging to perform this task manually due to the large number of records, I suggest using custom code. You can write a script that reads from your file, fetches the contact records, and deletes the relationship using the following code snippet:

    $tagBean = BeanFactory::retrieveBean('Tags', $tag_id);
    if ($tagBean)

    {
         $tagBean->load_relationship('contacts_link');
         $tagBean->contacts_link->delete($contact_id);
    }

    Make sure to replace $tag_id with the actual Tag ID and $contact_id with the actual Contact ID.

    Alternatively, you can use the API endpoint to unlink records, but this method will only handle one record at a time. For bulk operations, custom code is a more efficient solution.

    Hope this information helps !!

    Thanks and Regards,

    Ramya Katram,

    www.bhea.com

  •   ,

      has a great answer for you, but it does require code.


    If you are On-Site, feeling adventurous, and you know your tag_id, you could hazard a DB update, but know that this will bypass any bean logic.

    update
    tag_bean_rel
    set deleted = 1,
    date_modified = utc_timestamp()
    where bean_module = 'Contacts'
    and tag_id = 'c29334c8-4a11-11eb-98f2-001a4a160206'
    and deleted = 0

    (the tag_id in the example is obviously made up and would have to be replaced with your tag id)

    I believe that for Cloud customers you could ask Support to execute SQL commands for you, which may be an option for you.

    FrancescaS

  • Hi Francesca,

    Since they are looking for specific contacts under that tag, don't you think the DB query above will untag all the contacts under a specific tag?

  • Yes, you are correct  

    I misunderstood the question. The SQL I posted above (and cannot edit) WILL remove the tag from EVERY contact.

    Though the SQL could be modified for specific contact ids (replace the list of bean_id with the appropriate Contact IDs and the tag_id with the appropriate Tag id:

    update
    tag_bean_rel
    set deleted = 1,
    date_modified = utc_timestamp()
    where bean_module = 'Contacts'
    and tag_id = 'c29334c8-4a11-11eb-98f2-001a4a160206'
    and bean_id in ( 'cfb99aa0-b652-11ef-9161-001a4a1602ad', 'cfa0c53e-b652-11ef-a3e1-001a4a1602ad')
    and deleted = 0

  • for the sake of completeness in case others come across this post, if you want to remove a Tag from everyone, just deleting the Tag itself will do that, no need for SQL Slight smile

    .

    CRM Business Consultant

  • Very good point but it will remove the tag from all modules where that Tag is used, not just Contacts.

  • Thanks for the clarification. We are a cloud customer. This solution might work, but getting all the contact IDs will take equally much time as just manually taking it off them. :) 
    I'll see if support has an idea. Ideally we'd like to use the "mass update" function to be able to also remove and not just add.