Answers.Body: <p>Looks like a regression from <a href="https://github.com/civicrm/civicrm-core/commit/99f76265c5a462cae4fd59d1a8045492719f7811#diff-0d91c6437ca76cd02208c7c19699d883631d330427a765f4b7ccc323b42ff12d" rel="nofollow noreferrer">commit#99f7626</a></p>
  <p>Could you try below patch?</p>
  <pre><code>diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php
  index ac2a002c4c..a314f5e736 100644
  --- a/CRM/Financial/Page/AJAX.php
  +++ b/CRM/Financial/Page/AJAX.php
  @@ -170,13 +170,24 @@ class CRM_Financial_Page_AJAX {
           switch ($op) {
             case 'assign':
             case 'remove':
  -            if ($op == 'remove' || $op == 'assign') {
  -              $params = [
  -                'entity_id' =&gt; $recordID,
  -                'entity_table' =&gt; 'civicrm_financial_trxn',
  -                'batch_id' =&gt; $entityID,
  -              ];
  +            $params = [
  +              'entity_id' =&gt; $recordID,
  +              'entity_table' =&gt; 'civicrm_financial_trxn',
  +              'batch_id' =&gt; $entityID,
  +            ];
  +
  +            if ($op == 'remove') {
  +              try {
  +                $id = civicrm_api3('EntityBatch', 'getvalue', $params + [
  +                  'return' =&gt; 'id',
  +                ]);
  +                $params = ['id' =&gt; $id];
  +              }
  +              catch (Exception $e) {
  +                $errorMessage = $e-&gt;getMessage();
  +              }
               }
  +
               break;
   
             case 'close':
  @@ -214,9 +225,9 @@ class CRM_Financial_Page_AJAX {
                 'status_id' =&gt; $redirectStatus,
               ];
             }
  -          if ($errorMessage ?? FALSE) {
  -            $response = ['status' =&gt; $errorMessage];
  -          }
  +        }
  +        if ($errorMessage ?? FALSE) {
  +          $response = ['status' =&gt; $errorMessage];
           }
         }
       }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-01T13:49:10.680Z
Answers.LastActivityDate: 2022-02-01T13:49:10.680Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I have an error when working with Accounting Batches. It's kind of hard to pin down - the front end gives the default / standard / very helpful. What I did was:</p>
  <ul>
  <li>add a new accounting Batch (Contributions &gt; Accounting Batches &gt; New Batch)</li>
  <li>Assign a contribution to the batch</li>
  <li>try to remove the contribution from the batch</li>
  </ul>
  <p>at this point I get:</p>
  <blockquote>
  <p>No response from the server. Check your internet connection and try reloading the page.</p>
  </blockquote>
  <p>message, but ConfigAndLog does give a bit more, i.e.:</p>
  <pre><code>$Fatal Error Details = array:3 [
    &quot;message&quot; =&gt; &quot;Cannot delete EntityBatch with no id.&quot;
    &quot;code&quot; =&gt; null
    &quot;exception&quot; =&gt; CRM_Core_Exception {#2039
      -errorData: array:1 [
        &quot;error_code&quot; =&gt; 0
      ]
      #cause: null
      -_trace: null
      #message: &quot;Cannot delete EntityBatch with no id.&quot;
      #code: 0
      #file: &quot;/var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/DAO.php&quot;
      #line: 958
      trace: {
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/DAO.php:958 {
          › if (empty($record['id'])) {
          ›   throw new CRM_Core_Exception(&quot;Cannot delete {$entityName} with no id.&quot;);
          › }
        }
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Batch/BAO/EntityBatch.php:39 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Financial/Page/AJAX.php:207 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Utils/REST.php:266 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Utils/REST.php:550 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php:279 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php:69 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php:36 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/drupal/civicrm.module:458 { …}
        /var/www/html/drupal7/includes/menu.inc:527 { …}
        /var/www/html/drupal7/index.php:21 { …}
      }
    }
  ]
  
  
  Jan 21 15:24:29  [debug] $backTrace = #0 /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Error.php(433): CRM_Core_Error::backtrace(&quot;backTrace&quot;, TRUE)
  #1 /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php(39): CRM_Core_Error::handleUnhandledException(Object(CRM_Core_Exception))
  #2 /var/www/html/drupal7/sites/all/modules/civicrm/drupal/civicrm.module(458): CRM_Core_Invoke::invoke((Array:3))
  #3 /var/www/html/drupal7/includes/menu.inc(527): civicrm_invoke(&quot;ajax&quot;, &quot;rest&quot;)
  #4 /var/www/html/drupal7/index.php(21): menu_execute_active_handler()
  #5 {main}
  
  </code></pre>
  <p>I'm at a bit of a loss where to go with this - could anyone give any pointers?</p>
  <p>I've just realised that this is also happening on a local buildkit drupal-clean. is this a bug?</p>
  <p>This is on CiviCRM 5.41.1</p>
  <p>Thanks in Advance</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-25T15:34:24.153Z
Comments.Text: What were you trying to do to cause the error?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-25T16:11:57.063Z
Comments.Text: Just added to the batch, and then tried to 'remove' the added item.
Comments.UserDisplayName: Marsh
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-25T16:18:34.347Z
Comments.Text: ...have updated the Question - sorry - didn't realise I'd not mentioned what I'd done. not ver useful!
Comments.UserDisplayName: Marsh
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-31T11:36:55.130Z
Comments.Text: I've also tried this locally on a fresh drupal9-clean install - I get the same issue just by starting a batch, adding a contribution, and attempting to remove the batch @PradeepNayak
Comments.UserDisplayName: Marsh
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-31T13:37:23.677Z
Comments.Text: could you try on dmaster?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-31T22:28:10.337Z
Comments.Text: I did. same story. will raise an issue in the morning
Comments.UserDisplayName: Marsh
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-01T08:39:38.257Z
Comments.Text: Issue raised here: https://lab.civicrm.org/dev/core/-/issues/3050
Comments.UserDisplayName: Marsh
Tags: <batches>
Title: EntityBatch with no ID error when removing items from Accounting Batches
ThreadText: # EntityBatch with no ID error when removing items from Accounting Batches
  
  (Asked by: username_0 on 2022-01-25)
  
  I have an error when working with Accounting Batches. It's kind of hard to pin down - the front end gives the default / standard / very helpful. What I did was:
  
  add a new accounting Batch (Contributions > Accounting Batches > New Batch)
  Assign a contribution to the batch
  try to remove the contribution from the batch
  
  at this point I get:
  
  No response from the server. Check your internet connection and try reloading the page.
  
  message, but ConfigAndLog does give a bit more, i.e.:
  $Fatal Error Details = array:3 [
    "message" => "Cannot delete EntityBatch with no id."
    "code" => null
    "exception" => CRM_Core_Exception {#2039
      -errorData: array:1 [
        "error_code" => 0
      ]
      #cause: null
      -_trace: null
      #message: "Cannot delete EntityBatch with no id."
      #code: 0
      #file: "/var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/DAO.php"
      #line: 958
      trace: {
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/DAO.php:958 {
          › if (empty($record['id'])) {
          ›   throw new CRM_Core_Exception("Cannot delete {$entityName} with no id.");
          › }
        }
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Batch/BAO/EntityBatch.php:39 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Financial/Page/AJAX.php:207 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Utils/REST.php:266 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Utils/REST.php:550 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php:279 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php:69 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php:36 { …}
        /var/www/html/drupal7/sites/all/modules/civicrm/drupal/civicrm.module:458 { …}
        /var/www/html/drupal7/includes/menu.inc:527 { …}
        /var/www/html/drupal7/index.php:21 { …}
      }
    }
  ]
  
  
  Jan 21 15:24:29  [debug] $backTrace = #0 /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Error.php(433): CRM_Core_Error::backtrace("backTrace", TRUE)
  #1 /var/www/html/drupal7/sites/all/modules/civicrm/CRM/Core/Invoke.php(39): CRM_Core_Error::handleUnhandledException(Object(CRM_Core_Exception))
  #2 /var/www/html/drupal7/sites/all/modules/civicrm/drupal/civicrm.module(458): CRM_Core_Invoke::invoke((Array:3))
  #3 /var/www/html/drupal7/includes/menu.inc(527): civicrm_invoke("ajax", "rest")
  #4 /var/www/html/drupal7/index.php(21): menu_execute_active_handler()
  #5 {main}
  
  
  I'm at a bit of a loss where to go with this - could anyone give any pointers?
  I've just realised that this is also happening on a local buildkit drupal-clean. is this a bug?
  This is on CiviCRM 5.41.1
  Thanks in Advance
  
  **Tags:** batches
  
  > **Comments:**
  > **username_1**: What were you trying to do to cause the error?  
  > **username_0**: Just added to the batch, and then tried to 'remove' the added item.  
  > **username_0**: ...have updated the Question - sorry - didn't realise I'd not mentioned what I'd done. not ver useful!  
  > **username_0**: I've also tried this locally on a fresh drupal9-clean install - I get the same issue just by starting a batch, adding a contribution, and attempting to remove the batch @PradeepNayak  
  > **username_1**: could you try on dmaster?  
  > **username_0**: I did. same story. will raise an issue in the morning  
  > **username_0**: Issue raised here: https://lab.civicrm.org/dev/core/-/issues/3050  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-02-01. Score: 0
  
  Looks like a regression from commit#99f7626
  Could you try below patch?
  diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php
  index ac2a002c4c..a314f5e736 100644
  --- a/CRM/Financial/Page/AJAX.php
  +++ b/CRM/Financial/Page/AJAX.php
  @@ -170,13 +170,24 @@ class CRM_Financial_Page_AJAX {
           switch ($op) {
             case 'assign':
             case 'remove':
  -            if ($op == 'remove' || $op == 'assign') {
  -              $params = [
  -                'entity_id' => $recordID,
  -                'entity_table' => 'civicrm_financial_trxn',
  -                'batch_id' => $entityID,
  -              ];
  +            $params = [
  +              'entity_id' => $recordID,
  +              'entity_table' => 'civicrm_financial_trxn',
  +              'batch_id' => $entityID,
  +            ];
  +
  +            if ($op == 'remove') {
  +              try {
  +                $id = civicrm_api3('EntityBatch', 'getvalue', $params + [
  +                  'return' => 'id',
  +                ]);
  +                $params = ['id' => $id];
  +              }
  +              catch (Exception $e) {
  +                $errorMessage = $e->getMessage();
  +              }
               }
  +
               break;
   
             case 'close':
  @@ -214,9 +225,9 @@ class CRM_Financial_Page_AJAX {
                 'status_id' => $redirectStatus,
               ];
             }
  -          if ($errorMessage ?? FALSE) {
  -            $response = ['status' => $errorMessage];
  -          }
  +        }
  +        if ($errorMessage ?? FALSE) {
  +          $response = ['status' => $errorMessage];
           }
         }
       }
  
  
  ---
  
  