<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question How to select only future date in date field using onsubmit client script in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572376#M1001042</link>
    <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have date field called return date. In that date field I need to select only present and future dates.&lt;/P&gt;&lt;P&gt;I can achieve this using ui policy, but I want to using client script.&lt;/P&gt;</description>
    <pubDate>Fri, 26 May 2023 10:32:00 GMT</pubDate>
    <dc:creator>sriram7</dc:creator>
    <dc:date>2023-05-26T10:32:00Z</dc:date>
    <item>
      <title>How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572376#M1001042</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have date field called return date. In that date field I need to select only present and future dates.&lt;/P&gt;&lt;P&gt;I can achieve this using ui policy, but I want to using client script.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 10:32:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572376#M1001042</guid>
      <dc:creator>sriram7</dc:creator>
      <dc:date>2023-05-26T10:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572383#M1001047</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/89122"&gt;@sriram7&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use below on change client script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var selectedDateNum = getDateFromFormat(newValue,g_user_date_time_format); 
   var today_date = new Date();
   var today_dateStr = formatDate(today_date, g_user_date_time_format); 
   var todayDateNum = getDateFromFormat(today_dateStr, g_user_date_time_format);
   if(selectedDateNum &amp;lt; todayDateNum) {
     g_form.addErrorMessage("Selected date cannot be less than today's date");
    } 
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 10:37:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572383#M1001047</guid>
      <dc:creator>Manmohan K</dc:creator>
      <dc:date>2023-05-26T10:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572403#M1001056</link>
      <description>&lt;P&gt;I want to populate error message in when i am submitting catalog form&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 10:43:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572403#M1001056</guid>
      <dc:creator>sriram7</dc:creator>
      <dc:date>2023-05-26T10:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572414#M1001061</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/89122"&gt;@sriram7&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can create a on submit client script in that case with below code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;function onSubmit(){

  var dateVal=g_form.getValue('your date field');
   var selectedDateNum = getDateFromFormat(dateVal ,g_user_date_time_format); 
   var today_date = new Date();
   var today_dateStr = formatDate(today_date, g_user_date_time_format); 
   var todayDateNum = getDateFromFormat(today_dateStr, g_user_date_time_format);
   if(selectedDateNum &amp;lt; todayDateNum) {
g_form.addErrorMessage("Selected date cannot be less than today's date");
return false;
    } 
return true;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 10:55:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572414#M1001061</guid>
      <dc:creator>Manmohan K</dc:creator>
      <dc:date>2023-05-26T10:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572427#M1001068</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/521991"&gt;@Manmohan K&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I am selecting tomorrows date it is throwing error&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sriram7_0-1685098489200.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/263806i644A863EFB2DCA9B/image-size/medium?v=v2&amp;amp;px=400" alt="sriram7_0-1685098489200.png" title="sriram7_0-1685098489200.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sriram7_1-1685098556025.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/263808i6C911A801D96820C/image-size/medium?v=v2&amp;amp;px=400" alt="sriram7_1-1685098556025.png" title="sriram7_1-1685098556025.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 10:56:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572427#M1001068</guid>
      <dc:creator>sriram7</dc:creator>
      <dc:date>2023-05-26T10:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572435#M1001073</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/89122"&gt;@sriram7&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you try below code and validate&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;function onSubmit(){

  var dateVal=new Date(g_form.getValue('return_date'));
 var todayDateNum = new Date();
   if(dateVal &amp;lt; todayDateNum) {
   g_form.addErrorMessage("Selected date cannot be less than today's date");
  return false;
    } 
return true;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 11:03:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572435#M1001073</guid>
      <dc:creator>Manmohan K</dc:creator>
      <dc:date>2023-05-26T11:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572468#M1001088</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/89122"&gt;@sriram7&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please write the onChange Client Script like this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var d = getDateFromFormat(newValue, g_user_date_format);
    var today = new Date();
    if (d &amp;lt; today) {
        alert('The date value cannot be before the current date and time. Please correct.');
        g_form.clearValue("access_date");
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If my answer resolves your issue then don't forget to mark it as correct and helpful.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Devender Kumar&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 11:44:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572468#M1001088</guid>
      <dc:creator>Devender Kumar</dc:creator>
      <dc:date>2023-05-26T11:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572535#M1001121</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/89122"&gt;@sriram7&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Please try the solution proposed in the thread below:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.servicenow.com/community/developer-forum/client-script-compare-a-field-date-with-current-time/m-p/2229685/page/2" target="_blank"&gt;https://www.servicenow.com/community/developer-forum/client-script-compare-a-field-date-with-current-time/m-p/2229685/page/2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;If my answer helped you in any way, please then mark it as helpful or correct.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 12:44:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572535#M1001121</guid>
      <dc:creator>SN_Learn</dc:creator>
      <dc:date>2023-05-26T12:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572554#M1001133</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/89122"&gt;@sriram7&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;no scripting is required. just use UI policy&lt;/P&gt;
&lt;P&gt;check this blog&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.servicenow.com/community/developer-articles/no-code-date-validations-through-catalog-ui-policies/ta-p/2297600" target="_blank" rel="noopener"&gt;No Code date validations through (Catalog) UI Policies&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 13:02:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2572554#M1001133</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-05-26T13:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2573443#M1001418</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/521991"&gt;@Manmohan K&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For today's date also it is showing error message. Error message needs to show only for past dates.&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 06:10:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2573443#M1001418</guid>
      <dc:creator>sriram7</dc:creator>
      <dc:date>2023-05-29T06:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2573466#M1001431</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/89122"&gt;@sriram7&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you get a chance to check the above link?&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 06:30:50 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2573466#M1001431</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-05-29T06:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only future date in date field using onsubmit client script</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2573503#M1001448</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/89122"&gt;@sriram7&lt;/a&gt;&amp;nbsp;, If you want to display the error message when you are clicking on Submit then&lt;/P&gt;&lt;P&gt;- create a hidden field(valid_date) with default value 'Yes'.&lt;/P&gt;&lt;P&gt;- Write an UI Policy to validate the selected date and set the value of hidden field 'valid_date' to yes/now using Run Script option of UI policy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pravindra1_1-1685344654622.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/264046i7CEDD2BFA3694B66/image-size/medium?v=v2&amp;amp;px=400" alt="Pravindra1_1-1685344654622.png" title="Pravindra1_1-1685344654622.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pravindra1_0-1685344526112.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/264045i60ADE2AF612E11CA/image-size/medium?v=v2&amp;amp;px=400" alt="Pravindra1_0-1685344526112.png" title="Pravindra1_0-1685344526112.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then write an On-Submit Client Script as below to check if valid date is selected and display error message:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pravindra1_2-1685344816483.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/264048i0AA05D8ABACED154/image-size/medium?v=v2&amp;amp;px=400" alt="Pravindra1_2-1685344816483.png" title="Pravindra1_2-1685344816483.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 07:21:05 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-select-only-future-date-in-date-field-using-onsubmit/m-p/2573503#M1001448</guid>
      <dc:creator>Pravindra1</dc:creator>
      <dc:date>2023-05-29T07:21:05Z</dc:date>
    </item>
  </channel>
</rss>

