Skip to Content
avatar image
Former Member

Current month in drop down

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?
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Jan 17 at 10:08 AM

    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);
    Add comment
    10|10000 characters needed characters exceeded

    • 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);
  • Jan 18 at 06:50 AM

    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);
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 18 at 05:38 AM

    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
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 22 at 12:58 AM

    Hi Arjit,

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

    Thanks

    Harish

    Add comment
    10|10000 characters needed characters exceeded