Skip to Content
0

Current month in drop down

Jan 15 at 12:52 AM

95

avatar image
Former Member

drop-down-snapshot.png

Hi,

I have a dashboard in which there is a month year filter where the filter always default's to previous month's data i have 4 years data in month year format in ascending order. Everything is working fine, Mustafa has helped me scripting this for the drop down. Below is the script which i have used for getting this displayed

on startup

var curr_date =APPLICATION.getInfo().dateNowInternalFormat;

var curr_year  = curr_date.substring(0,4);
var curr_year_num =Convert.stringToInt(curr_year);
var curr_month = curr_date.substring(4,6);

var previous_month_key ="";
var month_key ="";

var years =[""];
years.pop();

var months =["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

var curr_month_index =Convert.stringToInt(curr_month)-1;if(curr_month_index ==0){
	
	curr_year =Convert.floatToString(curr_year_num -1,"0000");
	curr_month_index =12;}

years.push(curr_year_num -1+"");
years.push(curr_year_num -2+"");
years.push(curr_year_num -3+"");
years.push(curr_year_num -4+"");

months.forEach(function(month,index){if(index< curr_month_index){
	
			month_key = curr_year +Convert.floatToString(index+1.0,"00");
			DDLB_MTHYR.addItem(month_key, months[index]+" " + curr_year);
			previous_month_key = month_key;}});

years.forEach(function(year,index){

	months.forEach(function(month,index){
	
		month_key = year +Convert.floatToString(index+1.0,"00");
		DDLB_MTHYR.addItem(month_key, months[index]+" " + year);});});

DDLB_MTHYR.setSelectedValue(previous_month_key);

and on the drop down variable i have used this script


DDLB_MTHYR:
APPLICATION.setVariableValue("ZMONTHYEAR1", DDLB_MTHYR.getSelectedValue());

now i just need to display current month in the drop down additionally what need's to be changed in the script for adding current month to the drop down?
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Arijit Das Jan 17 at 10:08 AM
0

On-Startup:

var curr_date =APPLICATION.getInfo().dateNowInternalFormat;

var curr_year  = curr_date.substring(0,4);
var curr_year_num =Convert.stringToInt(curr_year);
var curr_month = curr_date.substring(4,6);

//var previous_month_key ="";
var curr_month_key = curr_year + curr_month;

var month_key ="";

var years =[""];
years.pop();

var months =["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
/* 
var curr_month_index =Convert.stringToInt(curr_month)-1;
if(curr_month_index ==0){    
    curr_year =Convert.floatToString(curr_year_num -1,"0000");
    curr_month_index =12;
}
*/
var curr_month_index = Convert.stringToInt(curr_month);


years.push(curr_year_num -1+"");
years.push(curr_year_num -2+"");
years.push(curr_year_num -3+"");
years.push(curr_year_num -4+"");

months.forEach(function(month,index){
        if(index < curr_month_index){
            month_key = curr_year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + curr_year);
            //previous_month_key = month_key;
        }
    });

years.forEach(function(year,index){
        months.forEach(function(month,index){
            month_key = year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + year);
        });
    });

DDLB_MTHYR.setSelectedValue(curr_month_key);
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Arjit,

My requirement is in the month year filter it should always default to previous month plus it should also show current month in the filter. Code which you have sent shows current month in the drop down but it doesn't default it to previous month.

In my previous code it was defaulting to previous month, i tried to modify the code by adding the additional code you sent for current month to my code but it doesn't work.

Can you please help?

Thanks

Harish

0

OK. Here is the modified script:

On-Startup

var curr_date =APPLICATION.getInfo().dateNowInternalFormat;

var curr_year  = curr_date.substring(0,4);
var curr_year_num =Convert.stringToInt(curr_year);
var curr_month = curr_date.substring(4,6);

var previous_month_key ="";
//var curr_month_key = curr_year + curr_month;

var month_key ="";

var years =[""];
years.pop();

var months =["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
/* 
var curr_month_index =Convert.stringToInt(curr_month)-1;
if(curr_month_index ==0){    
    curr_year =Convert.floatToString(curr_year_num -1,"0000");
    curr_month_index =12;
}
*/
var curr_month_index = Convert.stringToInt(curr_month);
var prev_month_index = curr_month_index - 1;
var prev_month_year = curr_year;

if(curr_month_index == 1){    
    prev_month_year = Convert.floatToString(curr_year_num -1, "0000");
    prev_month_index = 12;
}

previous_month_key = prev_month_year + Convert.floatToString(prev_month_index, '00');

years.push(curr_year_num -1+"");
years.push(curr_year_num -2+"");
years.push(curr_year_num -3+"");
years.push(curr_year_num -4+"");

months.forEach(function(month,index){
        if(index < curr_month_index){
            month_key = curr_year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + curr_year);
            //previous_month_key = month_key;
        }
    });

years.forEach(function(year,index){
        months.forEach(function(month,index){
            month_key = year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + year);
        });
    });

DDLB_MTHYR.setSelectedValue(previous_month_key);
0
Arijit Das Jan 18 at 06:50 AM
0

Here you go:

var curr_date =APPLICATION.getInfo().dateNowInternalFormat;

var curr_year  = curr_date.substring(0,4);
var curr_year_num =Convert.stringToInt(curr_year);
var curr_month = curr_date.substring(4,6);

var previous_month_key ="";

var month_key ="";

var years =[""];
years.pop();

var months =["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

var curr_month_index = Convert.stringToInt(curr_month);
var prev_month_index = curr_month_index - 1;
var prev_month_year = curr_year;

if(curr_month_index == 1){    
    prev_month_year = Convert.floatToString(curr_year_num -1, "0000");
    prev_month_index = 12;
}

previous_month_key = prev_month_year + Convert.floatToString(prev_month_index, '00');

years.push(curr_year_num -4+"");
years.push(curr_year_num -3+"");
years.push(curr_year_num -2+"");
years.push(curr_year_num -1+"");



years.forEach(function(year,index){
        months.forEach(function(month,index){
            month_key = year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + year);
        });
    });
    
months.forEach(function(month,index){
        if(index < curr_month_index){
            month_key = curr_year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + curr_year);
        }
    });

DDLB_MTHYR.setSelectedValue(previous_month_key);
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 18 at 05:38 AM
0

Hi Arjit,

Thanks a lot Jan is coming i have slightly modified the script to show the years in ascending order, but the month is still being shown on top not at the bottom since the years are in ascending order.

var curr_date =APPLICATION.getInfo().dateNowInternalFormat;

var curr_year  = curr_date.substring(0,4);
var curr_year_num =Convert.stringToInt(curr_year);
var curr_month = curr_date.substring(4,6);

var previous_month_key ="";
//var curr_month_key = curr_year + curr_month;

var month_key ="";

var years =[""];
years.pop();

var months =["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
/* 
var curr_month_index =Convert.stringToInt(curr_month)-1;
if(curr_month_index ==0){    
    curr_year =Convert.floatToString(curr_year_num -1,"0000");
    curr_month_index =12;
}
*/
var curr_month_index = Convert.stringToInt(curr_month);
var prev_month_index = curr_month_index - 1;
var prev_month_year = curr_year;

if(curr_month_index == 1){    
    prev_month_year = Convert.floatToString(curr_year_num -1, "0000");
    prev_month_index = 12;
}

previous_month_key = prev_month_year + Convert.floatToString(prev_month_index, '00');

years.push(curr_year_num -4+"");
years.push(curr_year_num -3+"");
years.push(curr_year_num -2+"");
years.push(curr_year_num -1+"");

months.forEach(function(month,index){
        if(index < curr_month_index){
            month_key = curr_year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + curr_year);
            //previous_month_key = month_key;
        }
    });

years.forEach(function(year,index){
        months.forEach(function(month,index){
            month_key = year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + year);
        });
    });

DDLB_MTHYR.setSelectedValue(previous_month_key);

Can you let me know what i need to do to display current month at the bottom?

Thanks
Harish
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 22 at 12:58 AM
0

Hi Arjit,

What is it i need to change in the above java script to make current month appear at the bottom?

Thanks

Harish

Show 2 Share
10 |10000 characters needed characters left characters exceeded

I already answered:

var curr_date =APPLICATION.getInfo().dateNowInternalFormat;

var curr_year  = curr_date.substring(0,4);
var curr_year_num =Convert.stringToInt(curr_year);
var curr_month = curr_date.substring(4,6);

var previous_month_key ="";

var month_key ="";

var years =[""];
years.pop();

var months =["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

var curr_month_index = Convert.stringToInt(curr_month);
var prev_month_index = curr_month_index - 1;
var prev_month_year = curr_year;

if(curr_month_index == 1){    
    prev_month_year = Convert.floatToString(curr_year_num -1, "0000");
    prev_month_index = 12;
}

previous_month_key = prev_month_year + Convert.floatToString(prev_month_index, '00');

years.push(curr_year_num -4+"");
years.push(curr_year_num -3+"");
years.push(curr_year_num -2+"");
years.push(curr_year_num -1+"");



years.forEach(function(year,index){
        months.forEach(function(month,index){
            month_key = year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + year);
        });
    });
    
months.forEach(function(month,index){
        if(index < curr_month_index){
            month_key = curr_year + Convert.floatToString(index+1.0,"00");
            DDLB_MTHYR.addItem(month_key, months[index]+" " + curr_year);
        }
    });

DDLB_MTHYR.setSelectedValue(previous_month_key);
0
Former Member

Thanks a lot Arjit it has worked perfectly.

Thanks

Harish

0