Skip to content
Snippets Groups Projects

Civirules api action exception: Unable to remove/add tags.

Merged Pradeep Nayak requested to merge pradeep/civirules:master into master
1 unresolved thread

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
47 47 //alter parameters by subclass
48 48 $params = $this->alterApiParameters($params, $triggerData);
49 49
50 // check if record already exists in db.
51 try {
52 $id = civicrm_api3('EntityTag', 'getvalue', $params + ['return' => 'id']);
53 if (strtolower($action) == 'create') {
54 continue;
55 }
56 }
57 catch (CiviCRM_API3_Exception $e) {
58 if (strtolower($action) == 'delete') {
59 continue;
  • I dont get it why this working. If the api call EntityTag getvalue fails it gets into the catch part. My assumption is that it fails because the record does not exists in the system anymore.

    So what is the if statement checking? What happens when the if staement evaluates to false?

  • Use case:

    Action -> Delete:

    1. Check if a contact is already tagged.
    2. If yes then api will return id and contact will be removed from tag
    3. If No api will throw exception and will go into catch part and it will skip the foreach loop and move to next as we don't need to perform delete since the contact is not tagged

    Action -> Add

    1. Check if a contact is already tagged.
    2. If yes then api will return id and then it will go in if statement, So we don't need to add contact to tag which has been already tagged so skip the foreach loop and move to next.
    3. If No api will throw exception and will go into catch part and won't go in if statement since action is create so it will create entry entity tag table.

    EntityTag api throws exception when you try to perform delete action when contact is not tagged. This PR solves the problem as it checks before sending it to CiviCRM api.

  • I see why I was confused I forget that your changes are within a foreach a loop.

  • Please register or sign in to reply
  • merged

  • jaapjansma mentioned in commit 26b28d66

    mentioned in commit 26b28d66

  • My Pleasure :)

  • Please register or sign in to reply
    Loading