Answers.Body: <p>What doesn't help, is that the code for Report.php:402</p>
  
  <p><a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Report/Utils/Report.php#L402" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Report/Utils/Report.php#L402</a></p>
  
  <p>requires</p>
  
  <pre><code>if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) {
  </code></pre>
  
  <p>and otherwise</p>
  
  <pre><code>  $is_error = 1;
    // ...
    $messages[] = 'Did not find valid instance to execute';
  </code></pre>
  
  <p>The 'name' reported for my custom report is more like</p>
  
  <pre><code>com.foo.bar
  </code></pre>
  
  <p>.. is that a bug, or some requirement I missed ?</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-29T19:10:20.007Z
Answers.Text: Did you create it with [civix](https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-report) or manually? For use with the standard extension autoloader it would end up in a subfolder CRM/Myextension/Form/Report/SomeReport.php and be called CRM_Myextension_Form_Report_SomeReport. So yes in a sense it's currently required to have Form in it, but it probably shouldn't be, and it shouldn't be enforced the way it is with strstr().
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-30T08:29:08.277Z
Answers.Text: @demerit thanks for your response. I made them manually; CiviX didn't exist at the time I made those ... funny the problem only arises in the mail, not in the report online.
Answers.UserDisplayName: commonpike
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-29T16:22:08.060Z
Answers.LastActivityDate: 2020-04-29T16:22:08.060Z
Answers.UserDisplayName: commonpike
Body: <p>All of my custom report mail_report jobs give this error, both through cron and when triggered manually:</p>
  
  <blockquote>
    <p>"Did not find valid instance to execute"</p>
  </blockquote>
  
  <p>The report is defined as </p>
  
  <pre><code>class com_foo_bar extends CRM_Report_Form {
  </code></pre>
  
  <p>It is stored as an extension in </p>
  
  <pre><code>[civicrm.files]/ext/custom
  </code></pre>
  
  <p>For example, report 70 works fine in a webbrowser .. it is at </p>
  
  <p><a href="https://mydomain.com/bla/civicrm/report/instance/70" rel="nofollow noreferrer">https://mydomain.com/bla/civicrm/report/instance/70</a></p>
  
  <p>But the mail_report job log says</p>
  
  <blockquote>
    <p>Entity: Job Action: mail_report Summary Finished execution of yyy with result: Failure, Error message: Report Mail
    Triggered... Did not find valid instance to execute Details</p>
    
    <p>Parameters raw (from db settings):  instanceId=70 format=csv</p>
    
    <p>Parameters parsed (and passed to API method): 
    a:3:{s:7:"version";i:3;s:10:"instanceId";s:2:"70";s:6:"format";s:3:"csv";}</p>
    
    <p>Full message:  Finished execution of yyy with
    result: Failure, Error message: Report Mail Triggered... Did not find
    valid instance to execute</p>
  </blockquote>
  
  <p>The same happens when called from the command line. If job.mail_report is called on a regular report, it returns results. But if it is called on my custom reports, it returns</p>
  
  <pre><code>$ drush -u cron civicrm-api job.mail_report instanceId=70 format=csv sendmail=0 
  Report Mail Triggered...                                                                                                                                                                             [error]
  Did not find valid instance to execute
  Array
  (
      [is_error] =&gt; 1
      [error_message] =&gt; Report Mail Triggered...
  Did not find valid instance to execute
  )
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$ php bin/cli.php -s mydomain.com -u cron -p XXXXXX -e Job -a mail_report --instanceId=70 --format=csv --sendmail=0
  Report Mail Triggered...
  Did not find valid instance to execute
  Died during callApi
  </code></pre>
  
  <p>Any ideas ?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-06T10:02:15.597Z
Comments.Text: can you cross check that instanceId and format parameter on separate line for instance id 70?
Comments.UserDisplayName: Sunil Pawar
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-09T08:50:50.060Z
Comments.Text: You can see from the details it is parsed correctly - but also, when calling from the command line cli.php, both calls are 100% the same apart from the instanceId.
Comments.UserDisplayName: commonpike
Tags: <email><civireport><cron><5.15.2>
Title: My custom reports work fine, but mail_report fails
ThreadText: # My custom reports work fine, but mail_report fails
  
  (Asked by: username_0 on 2020-03-01)
  
  All of my custom report mail\_report jobs give this error, both through cron and when triggered manually:
  
  > "Did not find valid instance to execute"
  
  The report is defined as
  
  ```
  class com_foo_bar extends CRM_Report_Form {
  
  ```
  
  It is stored as an extension in
  
  ```
  [civicrm.files]/ext/custom
  
  ```
  
  For example, report 70 works fine in a webbrowser .. it is at
  
  <https://mydomain.com/bla/civicrm/report/instance/70>
  
  But the mail\_report job log says
  
  > Entity: Job Action: mail\_report Summary Finished execution of yyy with result: Failure, Error message: Report Mail
  > Triggered... Did not find valid instance to execute Details
  >
  > Parameters raw (from db settings): instanceId=70 format=csv
  >
  > Parameters parsed (and passed to API method):
  > a:3:{s:7:"version";i:3;s:10:"instanceId";s:2:"70";s:6:"format";s:3:"csv";}
  >
  > Full message: Finished execution of yyy with
  > result: Failure, Error message: Report Mail Triggered... Did not find
  > valid instance to execute
  
  The same happens when called from the command line. If job.mail\_report is called on a regular report, it returns results. But if it is called on my custom reports, it returns
  
  ```
  $ drush -u cron civicrm-api job.mail_report instanceId=70 format=csv sendmail=0 
  Report Mail Triggered...                                                                                                                                                                             [error]
  Did not find valid instance to execute
  Array
  (
      [is_error] => 1
      [error_message] => Report Mail Triggered...
  Did not find valid instance to execute
  )
  
  ```
  
  or
  
  ```
  $ php bin/cli.php -s mydomain.com -u cron -p XXXXXX -e Job -a mail_report --instanceId=70 --format=csv --sendmail=0
  Report Mail Triggered...
  Did not find valid instance to execute
  Died during callApi
  
  ```
  
  Any ideas ?
  
  **Tags:** email, civireport, cron, 5.15.2
  
  > **Comments:**
  > **username_1**: can you cross check that instanceId and format parameter on separate line for instance id 70?  
  > **username_0**: You can see from the details it is parsed correctly - but also, when calling from the command line cli.php, both calls are 100% the same apart from the instanceId.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-04-29. Score: 1
  
  What doesn't help, is that the code for Report.php:402
  
  <https://github.com/civicrm/civicrm-core/blob/master/CRM/Report/Utils/Report.php#L402>
  
  requires
  
  ```
  if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) {
  
  ```
  
  and otherwise
  
  ```
    $is_error = 1;
    // ...
    $messages[] = 'Did not find valid instance to execute';
  
  ```
  
  The 'name' reported for my custom report is more like
  
  ```
  com.foo.bar
  
  ```
  
  .. is that a bug, or some requirement I missed ?
  
  > **Comments:**
  > **username_2**: Did you create it with [civix](https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-report) or manually? For use with the standard extension autoloader it would end up in a subfolder CRM/Myextension/Form/Report/SomeReport.php and be called CRM_Myextension_Form_Report_SomeReport. So yes in a sense it's currently required to have Form in it, but it probably shouldn't be, and it shouldn't be enforced the way it is with strstr().  
  > **username_0**: @username_2 thanks for your response. I made them manually; CiviX didn't exist at the time I made those ... funny the problem only arises in the mail, not in the report online.  
  
  ---
  
  