Focal Point
[CLOSED]JS for first day of current month

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3597004386

August 12, 2016, 10:31 AM
MG
[CLOSED]JS for first day of current month
Good Morning all,

I have written a js function to add to my html page to populate a calendar with the first day of the current month. I think I have the code correct I get the alert when I run it outside of WF however when I put it in the html composer it doesn't do anything. Here is the code. Any help would be appreciated.

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
//add onInitialUpdate() function to make changes before initial run of the reports
function newdate_start() {
var date = new Date();var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var startdate = (firstDay.getMonth() + 1) + '/' + (firstDay.getDate()) + '/' + firstDay.getFullYear();
alert(startdate);}
}

This message has been edited. Last edited by: <Emily McAllister>,


WebFOCUS 8.05
Windows , Excel, PDf, HTML
August 12, 2016, 11:01 AM
Tony A
How are you calling your function? If you do not call it then it will not execute.

If you need this to run after the document is fully loaded then look at the line above your function - there's a big clue there!

Alternatively you could use a $(document).ready() call.

If none of this means anything to you then you may benefit by visiting w3schools.com and running through some tutorials on HTML, JavaScript and jQuery.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
August 12, 2016, 12:25 PM
GavinL
If we take your code and clean it up so we can see possible issues, we get this:

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
	//add onInitialUpdate() function to make changes before initial run of the reports
	
	function newdate_start() {
		var date = new Date();var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
		var startdate = (firstDay.getMonth() + 1) + '/' + (firstDay.getDate()) + '/' + firstDay.getFullYear();
		alert(startdate);
	}
}


Did you mean to put newdate_start() method inside of the window_onload() method?

Maybe you meant to do this:
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
	//add onInitialUpdate() function to make changes before initial run of the reports
	
	newdate_start();
}

function newdate_start() {
	var date = new Date();var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
	var startdate = (firstDay.getMonth() + 1) + '/' + (firstDay.getDate()) + '/' + firstDay.getFullYear();
	alert(startdate);
}




- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
August 12, 2016, 02:53 PM
MG
Gavin,
Thank you and sorry if the code pasted in poorly.
My explanation of my issue sucked, What I need to do is get the first day of the current month, load it into the calendar1 box in my html form so that all reports in my portal run with that as the default start date. I already have the end date set the way I need it, I just don't know anything about where to add JS inside the composer to make it work, and the solutions I found in the knowledge base don't do what I need. Thanks again for the information I think if I understand your answer and do it this way it should do what I want to do.


WebFOCUS 8.05
Windows , Excel, PDf, HTML
August 15, 2016, 04:34 AM
Wep5622
That function can be reduced to:
function newdate_start() {
	var date = new Date();	// Current day, this month
	date.setDate(1);	// Start of current month

	// I concatenate strings like this; the result is the same as your concat.
	var startdate = ([date.getMonth() +1, date.getDate(), date.getFullYear()]).join('/');
//	alert(startdate);

	// Use it in an IBI date control using JQuery (don't forget the leading #)
	$('#uniqueIdentifierOfYourDateControl').val(startdate);
}


Now it is possible that the value you set this way on load gets overwritten by the IBI chaining code, which runs code to fill controls on load as well. If that happens, move the call to this function into a (new) function onInitialUpdate().


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
August 15, 2016, 11:03 AM
Barry Solomon
Hi MG

Try this

function newdate_start() {
var date = new Date();var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var startdate = (firstDay.getMonth() + 1) + '/' + (firstDay.getDate()) + '/' + firstDay.getFullYear();
alert(startdate);
IbComposer_setCurrentSelection('calendar1',startdate, false);

}

Best of Luck
Barry


WebFOCUS 8
Windows, All Outputs
August 15, 2016, 12:12 PM
MG
Hi Barry,
Long time no talk to....... It is great to hear from you. Thanks for the suggestion, it didn't fix the issue I was having however your input is always welcome.


WebFOCUS 8.05
Windows , Excel, PDf, HTML
August 15, 2016, 12:19 PM
MG
Thanks for all the information and suggestions, I now have my calendar control displaying the first day of the current month in the control,,,, YEA, only one issue left to resolve. All of the reports in the portal are running on the default date in the fexes rather than with the new default in the cal control...... can't just remove the default, that doesn't work either.... I am sure this is something real simple that I am just missing..... oh Monday... how I lov you...NOT


WebFOCUS 8.05
Windows , Excel, PDf, HTML
September 06, 2016, 04:34 PM
Tamra
MG,

I see you asked another question. If the parameters are not being passed to the report add in the following at the top of the focexec:

-SET &ECHO=ALL;
-? &

Once the report appears - right mouse click and select view source, scroll until you see the list of variables appear ( usually green text). Check to see if your variables are listed.
Check within the code to see if the values are being picked up.


WebFOCUS Version 8 Technical Library
Above is the link to the document library. Click the "+" to open the links. Assuming you are using Dev Studio along with BI Portal - refer to the Developer Studio, Reporting Language, Reporting Tools and Business Inteligence Poral links for further documentation.

Post another topic for this specific question - this might generate more assistance for you too.

Thank you for participating in the Focal Point Forum.

Kind Regards,
Tamra Colangelo
IBI Focal Point Moderator


WebFOCUS 8x - BI Portal, Developer Studio, App Studio, Excel, PDF, Active Formats and HTML5
September 07, 2016, 08:56 AM
Francis Mariani
In an HTML Composer edited HTML file, you will find these two comments:

// TODO: Add your event handler code here
	//add onInitialUpdate() function to make changes before initial run of the reports


As Wep5622 mentioned, heed them.

Create a function called onInitialUpdate(), then put all the JS that needs to be executed upon load.

Something like:

...
function onInitialUpdate()
{
    newdate_start();
}
...



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server