Body: <p>Drupal 7.63
  Civi 5.4</p>
  
  <p>I have a Drupal webform for my contribution page and I want to allow donors that select "Is Recurring" the option to set the number of months for it to recur. So I have a Contribution custom data field "Recurring for X months" I am then using CiviRules to put that input into civicrm_contribution_recur > installments</p>
  
  <p>I have a CiviRule set to trigger with Contribution is Added, I have no conditions set, and my Action is a custom action. </p>
  
  <p>I have a watchdog built into my code so I can trouble shoot the code.</p>
  
  <pre><code>  protected function getApiEntity() {
      return 'ContributionRecur';
    }
  
    protected function getApiAction() {
      return 'Create';
    }
  
    protected function alterApiParameters($params, 
        CRM_Civirules_TriggerData_TriggerData $triggerData) {
      $contribution = $triggerData-&gt;getEntityData("Contribution");
  
      watchdog('CONTRIBUTION TRIGGER DATA', var_export($contribution, true));
  
      $params['id'] = $contribution['contribution_recur_id'];
  
      if ($contribution['custom_67'] &gt; 1) {
          $params['installments'] = $contribution['custom_67'];
      }
  
      watchdog('CONTRIBUTION PARAMS', var_export($params, true));
  
      return $params;
    }
  </code></pre>
  
  <p>In the Drupal logs I am seeing the arrays from the watchdog. However, custom_67 value is empty (custom_67 is listed in the array). If I run a Contribution Get in the API Explorer, the array includes values for custom_67 for the contribution I just made. I am now testing with real live contributions rather than the test Payment Processor to be sure that everything is fully functioning.</p>
  
  <p>I created a new CiviRule using "contribution is changed" and used the same above action. Then I used the API Explorer >Contribution > Create and changed the Amount &amp; Recurring for X (custom_67) to a different # for a particular contribution ID. It worked, it put the custom_67 # into contribution_recur > installments. However, it put in the old number not the new number.</p>
  
  <p>This lead me to think that maybe the CiviRules was triggering before the database finished writing to the custom table, so I added a 1 minute delay to the rule. I still get nothing returned in my watchdog arrays for values in custom_67.</p>
  
  <p>Any ideas why my Action Trigger Data is not getting values for custom_67?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-20T07:16:15.407Z
Comments.Text: What could be the case is that the contribution is written tot the database but the contribution recur entity not yet. So maybe you could use a trigger contribution recur is added?
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-20T09:24:09.800Z
Comments.Text: Doesn't answer your question but I've had similar issues.  The process is very dependent on the order of operations and for contributions, there can be many different things being updated.  A higher-level logical hook would be useful so that you can say 'when Civi has finished doing its stuff for this set of contribution things, run my code' rather than needing to figure whether you need to be triggering from a contribution, recurring contribution, line item, custom value etc.
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-20T13:20:29.863Z
Comments.Text: Actually ideally the hook that triggers the CiviCRM stuff should run off      CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, <classname>', $callBackParams) rather than directly from the post hook
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-20T16:19:31.537Z
Comments.Text: Jaap Jansma, I did try triggering off the Recur added (just forgot to say that I tried that) but that is written first so that the ID is added contribution > contribution_recur_id  I also looked to see if I could trigger off the custom table, etc.
Comments.UserDisplayName: Iowa Boy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-20T16:23:05.887Z
Comments.Text: ErikH, I will start looking at using your trigger.
Comments.UserDisplayName: Iowa Boy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-18T23:40:59.797Z
Comments.Text: Aidan mention finding a hook after everything is done. Does anyone know of hook that does that? I have tried the CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, <classname>', $callBackParams) with the ContributionRecur but it is still happening too soon.
Comments.UserDisplayName: Iowa Boy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-17T01:56:10.347Z
Comments.Text: Is there any way to have the rule trigger when an entry is added to the custom table?
Comments.UserDisplayName: Iowa Boy
Tags: <civirules>
Title: Need help with CiviRules Custom Action
ThreadText: # Need help with CiviRules Custom Action
  
  (Asked by: username_0 on 2019-02-20)
  
  Drupal 7.63
  Civi 5.4
  
  I have a Drupal webform for my contribution page and I want to allow donors that select "Is Recurring" the option to set the number of months for it to recur. So I have a Contribution custom data field "Recurring for X months" I am then using CiviRules to put that input into civicrm\_contribution\_recur > installments
  
  I have a CiviRule set to trigger with Contribution is Added, I have no conditions set, and my Action is a custom action.
  
  I have a watchdog built into my code so I can trouble shoot the code.
  
  ```
    protected function getApiEntity() {
      return 'ContributionRecur';
    }
  
    protected function getApiAction() {
      return 'Create';
    }
  
    protected function alterApiParameters($params, 
        CRM_Civirules_TriggerData_TriggerData $triggerData) {
      $contribution = $triggerData->getEntityData("Contribution");
  
      watchdog('CONTRIBUTION TRIGGER DATA', var_export($contribution, true));
  
      $params['id'] = $contribution['contribution_recur_id'];
  
      if ($contribution['custom_67'] > 1) {
          $params['installments'] = $contribution['custom_67'];
      }
  
      watchdog('CONTRIBUTION PARAMS', var_export($params, true));
  
      return $params;
    }
  
  ```
  
  In the Drupal logs I am seeing the arrays from the watchdog. However, custom\_67 value is empty (custom\_67 is listed in the array). If I run a Contribution Get in the API Explorer, the array includes values for custom\_67 for the contribution I just made. I am now testing with real live contributions rather than the test Payment Processor to be sure that everything is fully functioning.
  
  I created a new CiviRule using "contribution is changed" and used the same above action. Then I used the API Explorer >Contribution > Create and changed the Amount & Recurring for X (custom\_67) to a different # for a particular contribution ID. It worked, it put the custom\_67 # into contribution\_recur > installments. However, it put in the old number not the new number.
  
  This lead me to think that maybe the CiviRules was triggering before the database finished writing to the custom table, so I added a 1 minute delay to the rule. I still get nothing returned in my watchdog arrays for values in custom\_67.
  
  Any ideas why my Action Trigger Data is not getting values for custom\_67?
  
  **Tags:** civirules
  
  > **Comments:**
  > **username_1**: What could be the case is that the contribution is written tot the database but the contribution recur entity not yet. So maybe you could use a trigger contribution recur is added?  
  > **username_2**: Doesn't answer your question but I've had similar issues.  The process is very dependent on the order of operations and for contributions, there can be many different things being updated.  A higher-level logical hook would be useful so that you can say 'when Civi has finished doing its stuff for this set of contribution things, run my code' rather than needing to figure whether you need to be triggering from a contribution, recurring contribution, line item, custom value etc.  
  > **username_3**: Actually ideally the hook that triggers the CiviCRM stuff should run off      CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, <classname>', $callBackParams) rather than directly from the post hook  
  > **username_0**: username_1 Jansma, I did try triggering off the Recur added (just forgot to say that I tried that) but that is written first so that the ID is added contribution > contribution_recur_id  I also looked to see if I could trigger off the custom table, etc.  
  > **username_0**: username_3, I will start looking at using your trigger.  
  > **username_0**: username_2 mention finding a hook after everything is done. Does anyone know of hook that does that? I have tried the CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, <classname>', $callBackParams) with the ContributionRecur but it is still happening too soon.  
  > **username_0**: Is there any way to have the rule trigger when an entry is added to the custom table?  
  
  ---
  
  ## 0 answers
  
  