Answers.Body: <p>Check to see what your default email location type is and add that as the second condition: &quot;AND Location Type = [default]&quot;</p>
  <p>The issue was that both email table entries (Home &amp; Billing) are initially created as Primary. But the non-default email is then updated to not Primary. So the CiviRule processes before the non-default email update happens. .</p>
  <p>Thanks to ErikH and Aidan for their help in troubleshooting this.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-11T07:34:13.917Z
Answers.Text: That works for you Iowa Boy, but is not a generic fix. People could use other location type than home as default ones. The "real" fix should check why it compares the same value twice. Also, I would recommend to change your fix to check for the default location type so it remains flexible?
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-11T15:51:29.320Z
Answers.Text: Thanks ErikH. Just to be sure I am understanding you, 1. I can change a setting so that the billing email is not set to primary in the Insert process? 2. or do i need to adjust the answer above to have step one check to see what is set as the default email location?   Or 3. You can submit the proper generic answer and I give it a vote.
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-11T16:22:04.787Z
Answers.Text: I meant step 2 for your fix :-) And I guess in CiviRules the fix would need to be to add a check to see if there are more primary ones or smthing like that. My concern with your fix would be that this would not be correct if someone decides to have another location type as Home as the default one? Glad you found your fix, could you please add an issue to the CiviRules repo (https://lab.civicrm.org/extensions/civirules) for the generic issue (which your fix only partially solves as stated above). And refer  to this thread? Could be a postCommit would also solve the issue.
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-10T23:09:06.063Z
Answers.LastActivityDate: 2020-11-11T23:47:35.053Z
Answers.LastEditDate: 2020-11-11T23:47:35.053Z
Answers.UserDisplayName: Iowa Boy
Body: <p>I have created a CiviRule that Triggers on &quot;Email address is added&quot; with a linked condition of &quot;Field Value Comparison Email.is_primary = 1&quot;</p>
  <p>It is triggering and the action is happening. However, it is happening 2Xs. Which shows an error message to our users.</p>
  <p>In API4, if I select Email &gt; get -&gt; Where Contact id = xxx; it shows 2 results.
  If I select Email &gt; get -&gt; Where Contact id = xxx &amp; -&gt;Where email is primary - yes; it shows 1 result.</p>
  <p>The activity that is happening when this triggers is a contribution from a first-time donor. Any ideas why the Link Condition above does not limit my trigger to 1X?
  Thanks</p>
  <p>Here are the screenshots of the Rule setup per request of jitendra
  <a href="https://i.sstatic.net/gymHm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/gymHm.png" alt="enter image description here" /></a>
  <a href="https://i.sstatic.net/m6Pxc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/m6Pxc.png" alt="enter image description here" /></a></p>
  <p>EDIT: I added more information being sent to the logs. I can now see the Email ID # along with the condition value (per suggestion of ErikH). It is not getting the correct condition on &quot;Email is Primary=1&quot;. That is showing 1 for both times but the email table has one with 1 and one with 0.</p>
  <p>I added to the condition &quot;&amp; Location Type=Home&quot; Now it just processes the rule 1x.</p>
  <p><a href="https://i.sstatic.net/v3YiW.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/v3YiW.jpg" alt="enter image description here" /></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-04T16:18:11.087Z
Comments.Text: I have also switched the condition to No. It did not trigger the CiviRule. I would have expected it to trigger 1x for either condition. The email table has 2 rows when a CRM user is created, one is Primary and one is not.
Comments.UserDisplayName: Iowa Boy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-05T07:44:08.717Z
Comments.Text: Can you check if the condition actually checks the correct values?
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-05T15:57:09.667Z
Comments.Text: How do I check that?
Comments.UserDisplayName: Iowa Boy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-06T08:28:05.810Z
Comments.Text: You  can debug the isValidCondition function in CRM_CivirulesConditions_Generic_ValueComparison
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-06T11:43:36.813Z
Comments.Text: Not sure if this depends on how your rule is configured. Can you add a screenshot for the complete set of triggers?
Comments.UserDisplayName: jitendra - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-07T16:33:21.327Z
Comments.Text: I checked the ValidCondition and it returns ConditionValue = 1 for both times
Comments.UserDisplayName: Iowa Boy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-07T21:02:30.040Z
Comments.Text: I added to my debug logs to show the Email Id as well. It is showing an incorrect Condition Value for one of the times.
Comments.UserDisplayName: Iowa Boy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-09T20:43:49.813Z
Comments.Text: Is logging enabled?  If so, check `log_civicrm_email` and see whether there are unexpected changes - eg it being created as primary and then updated to not primary.
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-10T16:40:02.793Z
Comments.Text: @ Aidan, you are correct. There are 3 entries for each email address. The Home address (location_ype = 1) has one entry. However, the Billing address (location_type = 5) has 2 entries. The initial entry is Insert & Primary = 1, the second entry is Update & Primary = 0.
Comments.UserDisplayName: Iowa Boy
Tags: <civirules>
Title: CiviRule triggers 2Xs
ThreadText: # CiviRule triggers 2Xs
  
  (Asked by: username_0 on 2020-11-04)
  
  I have created a CiviRule that Triggers on "Email address is added" with a linked condition of "Field Value Comparison Email.is\_primary = 1"
  
  It is triggering and the action is happening. However, it is happening 2Xs. Which shows an error message to our users.
  
  In API4, if I select Email > get -> Where Contact id = xxx; it shows 2 results.
  If I select Email > get -> Where Contact id = xxx & ->Where email is primary - yes; it shows 1 result.
  
  The activity that is happening when this triggers is a contribution from a first-time donor. Any ideas why the Link Condition above does not limit my trigger to 1X?
  Thanks
  
  Here are the screenshots of the Rule setup per request of username_2
  [![enter image description here](https://i.sstatic.net/gymHm.png)](https://i.sstatic.net/gymHm.png)
  [![enter image description here](https://i.sstatic.net/m6Pxc.png)](https://i.sstatic.net/m6Pxc.png)
  
  EDIT: I added more information being sent to the logs. I can now see the Email ID # along with the condition value (per suggestion of username_1). It is not getting the correct condition on "Email is Primary=1". That is showing 1 for both times but the email table has one with 1 and one with 0.
  
  I added to the condition "& Location Type=Home" Now it just processes the rule 1x.
  
  [![enter image description here](https://i.sstatic.net/v3YiW.jpg)](https://i.sstatic.net/v3YiW.jpg)
  
  **Tags:** civirules
  
  > **Comments:**
  > **username_0**: I have also switched the condition to No. It did not trigger the CiviRule. I would have expected it to trigger 1x for either condition. The email table has 2 rows when a CRM user is created, one is Primary and one is not.  
  > **username_1**: Can you check if the condition actually checks the correct values?  
  > **username_0**: How do I check that?  
  > **username_1**: You  can debug the isValidCondition function in CRM_CivirulesConditions_Generic_ValueComparison  
  > **username_2**: Not sure if this depends on how your rule is configured. Can you add a screenshot for the complete set of triggers?  
  > **username_0**: I checked the ValidCondition and it returns ConditionValue = 1 for both times  
  > **username_0**: I added to my debug logs to show the Email Id as well. It is showing an incorrect Condition Value for one of the times.  
  > **username_3**: Is logging enabled?  If so, check `log_civicrm_email` and see whether there are unexpected changes - eg it being created as primary and then updated to not primary.  
  > **username_0**: @ username_3, you are correct. There are 3 entries for each email address. The Home address (location_ype = 1) has one entry. However, the Billing address (location_type = 5) has 2 entries. The initial entry is Insert & Primary = 1, the second entry is Update & Primary = 0.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-11-10. Score: 2
  
  Check to see what your default email location type is and add that as the second condition: "AND Location Type = [default]"
  
  The issue was that both email table entries (Home & Billing) are initially created as Primary. But the non-default email is then updated to not Primary. So the CiviRule processes before the non-default email update happens. .
  
  Thanks to username_1 and username_3 for their help in troubleshooting this.
  
  > **Comments:**
  > **username_1**: That works for you username_0, but is not a generic fix. People could use other location type than home as default ones. The "real" fix should check why it compares the same value twice. Also, I would recommend to change your fix to check for the default location type so it remains flexible?  
  > **username_0**: Thanks username_1. Just to be sure I am understanding you, 1. I can change a setting so that the billing email is not set to primary in the Insert process? 2. or do i need to adjust the answer above to have step one check to see what is set as the default email location?   Or 3. You can submit the proper generic answer and I give it a vote.  
  > **username_1**: I meant step 2 for your fix :-) And I guess in CiviRules the fix would need to be to add a check to see if there are more primary ones or smthing like that. My concern with your fix would be that this would not be correct if someone decides to have another location type as Home as the default one? Glad you found your fix, could you please add an issue to the CiviRules repo (https://lab.civicrm.org/extensions/civirules) for the generic issue (which your fix only partially solves as stated above). And refer  to this thread? Could be a postCommit would also solve the issue.  
  
  ---
  
  