cancel
Showing results for 
Search instead for 
Did you mean: 

enabling a button according to time

Former Member
0 Kudos

Hi all,

I have a requirement of enabling a button according to system time ie from 9:00 am to 10:00 am I need to have the button functionality disabled for particular days. Is this type of functionality possible if so can anyone help me in how I can go about with it.

Thank you

Regards,

Preet

Accepted Solutions (1)

Accepted Solutions (1)

gill367
Active Contributor
0 Kudos

Hello Preet,

you can use the following code :-

this particular piece of code will enable the button for monday to friday and morning 9 am to evening 5 pm.

you need to write this code in wddoinit of your view and also bind the enable property of your button to one boolean attribute in context. for example here i have bound it to btnpro.


java.util.Calendar cl = Calendar.getInstance();  // get the current time and date
	  
	 int day = cl.get(cl.DAY_OF_WEEK);
	 int hour = cl.get(cl.HOUR_OF_DAY);
	 if((day >=  1 || day <= 5 )&&((hour >= 9 && hour <= 17)))
	 {

		 wdContext.currentContextElement().setBtnpro(true);
	 }
	 
	 else
	 {
		 wdContext.currentContextElement().setBtnpro(false);
	 }

Thanks

Sarbjeet Singh

Former Member
0 Kudos

Hi,

Adding to sarbjeet point we need to bind the button's enabled property to a context variable of type boolean and we need to modify these context variable in the wddoModify view as the above code.

Regards,

Raju Bonagiri

Former Member
0 Kudos

Hi Sarabjeet,

Thanks for your answer. It is working fine. But just wanted to correct one thing the days it considers from sunday ie sunday=1, monday=2, tuesday=3...friday=6.

Thank you

Regards,

Preet Kaur

gill367
Active Contributor
0 Kudos

Yeah preet you are right...

Sorry for that.

Thanks

Sarb

Answers (2)

Answers (2)

p330068
Active Contributor
0 Kudos

Hi Preet,

Yes, this will be possible but you need to play with calander, date methods to achive your requierment.

Then once you accomplish your requirement, try to enable/disable button based on the conditions.

Regards

Arun Jaiswal

former_member214651
Active Contributor
0 Kudos

Hi,

Try using the following code to get the time:

java.sql.Date dateValue = new Date(System.currentTimeMillis());
java.sqlTime timeValue = new Time(dateValue.getTime());
int finalValue = 24 - timeValue.getHours();
if(finalValue == 15)
{
	//Set the button enabled property to false;
}
else
{
	//Set the button enabled property to true;
}

Hope this helps you.

Regards,

Poojith MV