[SOLVED] Setting Start Values in Calendar Controls
I'm having a hard time setting the initial values for a Start and End date set of calendar controls. Start date needs to be a year before today, so it's computed. The only way to get a value into the control is by using a fex from the Requests zone and you would think that this would be easy. First of, as an aside, I don't see why a fex should be necessary. Why should I have to connect to a database just to set a couple of constants?
Currently my fex looks like this, although this has been evolving:
TABLE FILE CMSBESTPRACTICESDATA SUM COMPUTE ONEYEARAGO/MDYY = DTADD( '&YYMD', YEAR, -1 ); COMPUTE CURRENTDATE/MDYY = '&YYMD'; BY HIGHEST 1 SCHED_START_DT ON TABLE SET PAGE-NUM NOLEAD ON TABLE SET ASNAMES ON ON TABLE NOTOTAL ON TABLE PCHOLD FORMAT HTML ON TABLE SET HTMLEMBEDIMG ON ON TABLE SET HTMLCSS ON ON TABLE SET STYLE * INCLUDE = IBFS:/EDA/EDASERVE/_EDAHOME/ETC/warm.sty, $ ENDSTYLE END
Please don't tell me that I can set the current date part by checking the box in Settings. I know this. That isn't the problem.This message has been edited. Last edited by: mbondr,
WebFOCUS 8.2.04 (and climbing) Windows 10, AppStudio
July 03, 2019, 07:40 AM
Mike in DeLand
You can use javascript in your HTML page. Here's some that I stole and modified.
Use this in a WebFocus HTML Launch page if you need to default a calendar control to the first or last day of the current month. substitute your control names for "cal_StartDate" and "cal_EndDate".
if(typeof(bRuntime) != 'undefined') {
// TODO: Add your inline runtime code here
}
//Begin function window_onload
function window_onload() {
UpdateData();
// TODO: Add your event handler code here
//
// This gets today's date into mm/dd/yyyy format
var today = new Date();
var mm = today.getMonth() + 1;
var dd = '01';
var yyyy = today.getFullYear ();
if (mm < 10)
{mm = '0' + mm};
var beginningOfMonth = mm + '/01/' + yyyy;
document.getElementById("cal_StartDate").value = beginningOfMonth;
var d = new Date();
m = d.getMonth(); //current month
y = d.getFullYear(); //current year
var lastday = new Date(y,m+1,0); //this is last day of current month
//break it up so we can show it in mm/dd/yyyy format
var lastmm = lastday.getMonth() + 1;
if (lastmm < 10)
{lastmm = '0' + lastmm};
var lastdd = lastday.getDate ();
var lastyyyy = lastday.getFullYear ();
var endOfMonth = lastmm + '/' + lastdd + '/' + lastyyyy;
document.getElementById("cal_EndDate").value = endOfMonth;
//add onInitialUpdate() function to make changes before initial run of the reports
}
//End function window_onload
Webfocus 8 Windows, Linux
July 03, 2019, 08:08 AM
MartinY
Fex to set the default dates No need to have all these ON TABLE... and the output format must be XML
TABLE FILE CAR
SUM COMPUTE ONEYEARAGO /YYMD = DTADD(DT_CURRENT_DATE(), YEAR, -1);
COMPUTE CURRENTDATE/YYMD = DT_CURRENT_DATE();
BY COUNTRY NOPRINT
WHERE READLIMIT EQ 1;
WHERE RECORDLIMIT EQ 1;
ON TABLE PCHOLD FORMAT XML
END
-RUN
Then add this fex as a Request & Data Source within your HTML Associate the fex in the Settings of your Start calendar control as an Explicit (Request panel) and have the ONEYEARAGO in the "Value From" & "Display From" Do the same for your End calendar control but with the CURRENTDATE in the "Value From" & "Display From" Adjust both calendar range and other settings as you whish.
Other options may be available to set the default values, but depending on how your HTML is accessed, the options differ.
WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF In Focus since 2007
July 03, 2019, 11:35 AM
mbondr
Yay! Both techniques clearly laid out. I will make sure these are saved. Thanks!
WebFOCUS 8.2.04 (and climbing) Windows 10, AppStudio