Select Only particular day in date date field

srikanthsuri012
Mega Contributor

Hi,

 

Is possible to select particular day only in date.

find_real_file.png

Here er have to select only Monday .if i select apart form Monday tee form could be submit.

find_real_file.png

Regards,

Suri 

1 ACCEPTED SOLUTION

graham_c
Tera Guru

Hi Suri,

You would need to build a onChange client script that would check the date entered using the getDayOfWeek GlideDateTime function.

 

This gets the week day as a number (Monday = 1, Sunday = 7) which you can build logic to say if the day is not equal to 1 then clear the value and display an error message, advising to try again.

Example code below (untested)

var gdt = new GlideDateTime(g_form.getValue('fieldNameGoesHere'));
if(gdt.getDayOfWeek()!=1){
  g_form.setValue('fieldNameGoesHere', '');
  g_form.showFieldMsg('fieldNameGoesHere','You have entered an invalid date - please try again, selecting only a Monday','error');
}

Thanks

P.S. If this has been helpful or has answered your question please mark accordingly.

View solution in original post

4 REPLIES 4

graham_c
Tera Guru

Hi Suri,

You would need to build a onChange client script that would check the date entered using the getDayOfWeek GlideDateTime function.

 

This gets the week day as a number (Monday = 1, Sunday = 7) which you can build logic to say if the day is not equal to 1 then clear the value and display an error message, advising to try again.

Example code below (untested)

var gdt = new GlideDateTime(g_form.getValue('fieldNameGoesHere'));
if(gdt.getDayOfWeek()!=1){
  g_form.setValue('fieldNameGoesHere', '');
  g_form.showFieldMsg('fieldNameGoesHere','You have entered an invalid date - please try again, selecting only a Monday','error');
}

Thanks

P.S. If this has been helpful or has answered your question please mark accordingly.

Krish14
Mega Contributor

Graham, Can you please help me in this:

https://community.servicenow.com/community?id=community_question&sys_id=cb1391d5dbc163401cd8a345ca961959

srikanthsuri012
Mega Contributor

Thanks Graham,

 

srikanthsuri012
Mega Contributor

Hello,

 

Here the complete code for reference,

we need to write Script Include:

 

find_real_file.png

 

Client Script OnChange:

 

find_real_file.png

If you are working in a global Application :

Use:

var ga = new GlideAjax('Monday');

 

If you are working in any scoped application 

Use:

var ga = new GlideAjax('global.Monday');

 

Result:

find_real_file.png

 

Regards,

Suri