Page 1 of 2
Search when opening a form.
Posted: Thu Apr 22, 2021 11:21 am
by kknm
The form has RUN :: iFrame.
I added two buttons to it for searching by a range of dates (for the current month and the current year)
It is necessary to select the reflection by month when opening the form.
Code: Select all
nuAddActionButton('f_month', fMonth, 'nuSearchAction("",'+ year+'.'+month+')');
nuAddActionButton('f_year', year, 'nuSearchAction("",'+ year+')');
Re: Search when opening a form.
Posted: Thu Apr 22, 2021 11:27 am
by kev1n
Set a Hash Cookie with nuSetProperty() before performing the search
Code: Select all
nuSetProperty('year_filter', year)
and use that in your Browse SQL.
Code: Select all
WHERE (YEAR(your_date) = #year_filter# OR LOCATE('#', '#year_filter#') = 1)
Re: Search when opening a form.
Posted: Thu Apr 22, 2021 1:40 pm
by kknm
And if I need to get the same thing on a regular Browse-Form?
Re: Search when opening a form.
Posted: Thu Apr 22, 2021 1:43 pm
by kev1n
This also works with a normal Browse Form.
Re: Search when opening a form.
Posted: Thu Apr 22, 2021 2:46 pm
by kknm
Code: Select all
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (p_dat LIKE '2021') AND ( (CONVERT(p_dat USING utf8) LIKE "%2021%" OR CONV' at line 3
===SQL===========
SELECT pl_id,p_dat,p_pl,p_dop,p_com,p_dep,p_st
FROM plan
WHERE WHERE (p_dat LIKE '2021') AND ( (CONVERT(p_dat USING utf8) LIKE "%2021%" OR CONVERT(p_pl USING utf8) LIKE "%2021%" OR CONVERT(p_dop USING utf8) LIKE "%2021%" OR CONVERT(p_com USING utf8) LIKE "%2021%" OR CONVERT(p_dep USING utf8) LIKE "%2021%" OR CONVERT(p_st USING utf8) LIKE "%2021%") ) LIMIT 0, 15
Doesn't work in Browse-Form ...
Re: Search when opening a form.
Posted: Thu Apr 22, 2021 3:49 pm
by kev1n
Can you show your Browse SQL?
Re: Search when opening a form.
Posted: Thu Apr 22, 2021 4:24 pm
by kknm
Code: Select all
if(nuFormType() == 'browse'){
Data = new Date();
year = Data.getFullYear();
month = Data.getMonth();
// day = Data.getDate();
switch (month)
{
case 0: fMonth="январь"; break;
case 1: fMonth="февраль"; break;
case 2: fMonth="март"; break;
case 3: fMonth="апрель"; break;
case 4: fMonth="май"; break;
case 5: fMonth="июнь"; break;
case 6: fMonth="июль"; break;
case 7: fMonth="август"; break;
case 8: fMonth="сентябрь"; break;
case 9: fMonth="октябрь"; break;
case 10: fMonth="ноябрь"; break;
case 11: fMonth="декабрь"; break;
}
let formDate = Data.toISOString();
tmonth=formDate.substr(0,7);
//nuMessage([tmonth]);
nuSetProperty('year_filter',tmonth);
nuAddActionButton('f_month', fMonth, 'nuSearchAction("", tmonth)');
nuAddActionButton('f_year', year, 'nuSearchAction("", year)');
}
This is how button search works. But when opened, the form is empty.
My SQL-code
Code: Select all
SELECT
plan.*
FROM
plan
WHERE
(( DATE_FORMAT(p_dat,'%Y-%m') LIKE '#year_filter#'))
no errors
Re: Search when opening a form.
Posted: Thu Apr 22, 2021 4:40 pm
by kev1n
Modify these 2 lines:
Code: Select all
nuAddActionButton('f_month', fMonth, 'nuSearchAction("", '+ tmonth +')');
nuAddActionButton('f_year', year, 'nuSearchAction("", '+ year+ ')');
Re: Search when opening a form.
Posted: Fri Apr 23, 2021 9:35 am
by kknm
It doesn't work either.
If we apply nuGetBreadcrumb (0), then the filter is triggered when the form is loaded, but the form is constantly updated. We need to apply nuGetBreadcrumb (0); Just once - how to do it?
Re: Search when opening a form.
Posted: Fri Apr 23, 2021 4:05 pm
by kev1n
Should the form display all records when opened? Then you would this "OR LOCATE( ..." condition in your where clause that I posted earlier.