This topic is locked
[SOLVED]

Search API SetFieldValue Error

11/30/2023 3:29:42 AM
PHPRunner General questions
J
jacktonghk authorDevClub member

I have add a field "ETD_FiscalYear" to the search panel, filter panel and advanced search. As I would like to set a default search value '2021/2022' to this search field, I have added codes to the 'After Table Initialized' event of the search page. However, when I try to open the function, it popped up an error message

Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, bool given in C:\xampp\htdocs\SS Analysis\classes\searchclause.php:1400 Stack trace: #0 C:\xampp\htdocs\SS Analysis\classes\searchclause.php(1400): in_array('ETD_FiscalYear', false) #1 C:\xampp\htdocs\SS Analysis\include\tableau_sales_report1_settings.php(1456): SearchClause->setFieldValue('ETD_FiscalYear', '2021/2022') #2 C:\xampp\htdocs\SS Analysis\include\phpfunctions.php(2775): include_once('C:\xampp\htdocs...') #3 C:\xampp\htdocs\SS Analysis\classes\projectsettings.php(156): importTableSettings('tableau_sales_r...') #4 C:\xampp\htdocs\SS Analysis\classes\projectsettings.php(54): ProjectSettings->setTable('dbo.Tableau_Sal...') #5 C:\xampp\htdocs\SS Analysis\tableau_sales_report1_report.php(27): ProjectSettings->__construct('dbo.Tableau_Sal...') #6 {main} thrown in C:\xampp\htdocs\SS Analysis\classes\searchclause.php on line 1400

I don't know what's wrong with my code. I am using PHPR 10.91 and my codes are as below. Can anyone help? Thanks.

$table = "tableau_sales_report1";
$srchObj = SearchClause::getSearchObject($table);
$value = $srchObj->getFieldValue("ETD_FiscalYear");
if( $value == null ) {
$srchObj->setFieldValue("ETD_FiscalYear","2021/2022");
}

fhumanes 11/30/2023

Hello,

Could it be that the default operator is not correct?

I would try to do this other way: https://xlinesoft.com/phprunner/docs/searchapi_set_search_sql.htm

Greetings,
fernando

J
jacktonghk authorDevClub member 12/1/2023

Hi Fernado, thanks for your advice.

I found out that I shouldn't redefine $table even though it looks like the same, I just need to use it because $table is already assigned the correct value and may be some other information. After I removed the $table = "tableau_sales_report1"; line, it works fine.