<?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 Re: Users should not be able to enter a date that is more than one year in the future. in International Localization forum</title>
    <link>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949009#M441</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/711506"&gt;@kevin246her&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;This isn't really a topic for internationalization, but I can tell you that you essentially would want a server-side script (because it's more efficient - so think a before BR with a potential abort action at the earliest order on the table and a redirect back to current),&lt;BR /&gt;&lt;BR /&gt;In that script you would want two Date (or DateTime variables), one representing the field value as is, one representing today (using &lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideDateTimeAPI#r_GDT-GlideDateTime" target="_self"&gt;this&lt;/A&gt; + 1 year) to compare against.&lt;BR /&gt;&lt;BR /&gt;Use the API details here to review how to construct the use of "AddYears" in the GlideDateTime API:&lt;BR /&gt;&lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideDateTimeAPI#r_GDT-addYears_N" target="_blank"&gt;https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideDateTimeAPI#r_GDT-addYears_N&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;BR /&gt;kind regards&lt;/P&gt;</description>
    <pubDate>Fri, 31 May 2024 07:36:20 GMT</pubDate>
    <dc:creator>Alex Coope - SN</dc:creator>
    <dc:date>2024-05-31T07:36:20Z</dc:date>
    <item>
      <title>Users should not be able to enter a date that is more than one year in the future.</title>
      <link>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2948986#M439</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to restrict users from entering a date more than one year in advance. If they do, an error message should be displayed, and they should not be able to save the form. I've tried creating an on-submit client script, but it's not working. Can anyone suggest a solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 31 May 2024 07:15:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2948986#M439</guid>
      <dc:creator>kevin246her</dc:creator>
      <dc:date>2024-05-31T07:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Users should not be able to enter a date that is more than one year in the future.</title>
      <link>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949006#M440</link>
      <description>&lt;P&gt;Create an onChange client script, showing a message and emptying the field. That way the form can't be saved, since the field is mandatory (I assume, since you don't want the form saved without a date).&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var currentDate = new Date();
    var inputDate = new Date(newValue);

    // Calculate the difference in milliseconds
    var differenceInMillis = inputDate - currentDate;

    // Convert milliseconds to days
    var differenceInDays = differenceInMillis / (1000 * 60 * 60 * 24);

    // Check if the difference is more than 365 days (1 year)
    if (differenceInDays &amp;gt; 365) {
        g_form.showErrorBox('your_date_field', 'Date cannot be more than 1 year in the future.');
        g_form.setValue('your_date_field', '');
    } else {
        g_form.hideErrorBox('your_date_field');
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 31 May 2024 07:33:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949006#M440</guid>
      <dc:creator>Mark Manders</dc:creator>
      <dc:date>2024-05-31T07:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Users should not be able to enter a date that is more than one year in the future.</title>
      <link>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949009#M441</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/711506"&gt;@kevin246her&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;This isn't really a topic for internationalization, but I can tell you that you essentially would want a server-side script (because it's more efficient - so think a before BR with a potential abort action at the earliest order on the table and a redirect back to current),&lt;BR /&gt;&lt;BR /&gt;In that script you would want two Date (or DateTime variables), one representing the field value as is, one representing today (using &lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideDateTimeAPI#r_GDT-GlideDateTime" target="_self"&gt;this&lt;/A&gt; + 1 year) to compare against.&lt;BR /&gt;&lt;BR /&gt;Use the API details here to review how to construct the use of "AddYears" in the GlideDateTime API:&lt;BR /&gt;&lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideDateTimeAPI#r_GDT-addYears_N" target="_blank"&gt;https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideDateTimeAPI#r_GDT-addYears_N&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;BR /&gt;kind regards&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 07:36:20 GMT</pubDate>
      <guid>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949009#M441</guid>
      <dc:creator>Alex Coope - SN</dc:creator>
      <dc:date>2024-05-31T07:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Users should not be able to enter a date that is more than one year in the future.</title>
      <link>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949016#M442</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/7272"&gt;@Mark Manders&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;This is not advisable because we have API's to addYears with GlideDateTime, so introducing maths does not factor in timezone and daylightsaving periods, also your messages are hard-coded which is an internationalization infraction called a "&lt;A href="https://www.servicenow.com/community/international-localization/want-to-find-a-hardcoded-string-check-this-instance-scan/ta-p/2460714" target="_self"&gt;hard-coded string&lt;/A&gt;" (meaning it is never translatable),&lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;BR /&gt;Kind regards&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 07:40:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949016#M442</guid>
      <dc:creator>Alex Coope - SN</dc:creator>
      <dc:date>2024-05-31T07:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Users should not be able to enter a date that is more than one year in the future.</title>
      <link>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949032#M443</link>
      <description>&lt;P&gt;Daylight saving is a difference of an hour, how does that relate do a date field? And timezones can be ignored when you are checking on a date to see if it is a YEAR away.&lt;/P&gt;&lt;P&gt;Next to that: a solution was asked, without mentioning it should be translated or anything like that. Of course you don't want hard coded messages when you have multiple languages on an instance, but where was this mentioned to be a requirement? You are making assumptions that aren't based on anything. A solution was asked and based on the given information a possible solution was given. These can (and should) be tweaked to get the perfect solution, but you are getting date/time involved and translations, that were nowhere mentioned.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 07:50:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949032#M443</guid>
      <dc:creator>Mark Manders</dc:creator>
      <dc:date>2024-05-31T07:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Users should not be able to enter a date that is more than one year in the future.</title>
      <link>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949297#M444</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/711506"&gt;@kevin246her&lt;/a&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Simply create UI policy, no need of so much scripting. I have created a UI policy on change request table on planned_end_date field for you reference. give condition as below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I have given relative after 365 days from now in condition. here in condition instead of 365 days, you can give after 1 years from now and it will be more accurate as it will consider the leap year as well.&lt;/STRONG&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="PratikshaLang1_0-1717158152649.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/361343i4B8084EF62AB92D0/image-dimensions/653x307?v=v2" alt="PratikshaLang1_0-1717158152649.png" title="PratikshaLang1_0-1717158152649.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="PratikshaLang1_1-1717158288693.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/361344i8E40E1C9081F71A8/image-dimensions/700x337?v=v2" alt="PratikshaLang1_1-1717158288693.png" title="PratikshaLang1_1-1717158288693.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;Please mark my answer as helpful if it has helped you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 12:28:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/international-localization-forum/users-should-not-be-able-to-enter-a-date-that-is-more-than-one/m-p/2949297#M444</guid>
      <dc:creator>Pratiksha Lang1</dc:creator>
      <dc:date>2024-05-31T12:28:37Z</dc:date>
    </item>
  </channel>
</rss>

