<?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 restrict the 'Date' variable in a catalog item to only allow only the current month clickable in Virtual Agent forum</title>
    <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856396#M5345</link>
    <description>&lt;P&gt;We have a request to limit our users from selecting a date in a catalog request item to the current month only. For example, today is March 8, 2024, we want to ONLY allow any day in the current month (March) to be selectable. We do not want users being able to select a past date in a previous month, or a future date in the next month.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Mar 2024 21:52:06 GMT</pubDate>
    <dc:creator>Rakesh_Damji</dc:creator>
    <dc:date>2024-03-08T21:52:06Z</dc:date>
    <item>
      <title>How to restrict the 'Date' variable in a catalog item to only allow only the current month clickable</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856396#M5345</link>
      <description>&lt;P&gt;We have a request to limit our users from selecting a date in a catalog request item to the current month only. For example, today is March 8, 2024, we want to ONLY allow any day in the current month (March) to be selectable. We do not want users being able to select a past date in a previous month, or a future date in the next month.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 21:52:06 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856396#M5345</guid>
      <dc:creator>Rakesh_Damji</dc:creator>
      <dc:date>2024-03-08T21:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856640#M5352</link>
      <description>&lt;P&gt;Here are two general approaches you can use to restrict the clickable dates in a ServiceNow catalog item's 'Date' variable to only the current month:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Approach 1: UI Script (Client-Side)&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;Write a UI Script:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Create a UI script for the catalog item that will manipulate the date picker control.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Access the Date Picker:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Use JavaScript code to access the date picker element associated with the 'Date' variable. You might need to reference the variable name or a DOM element ID.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Filter Dates:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Write logic within the script to disable all dates except those within the current month. This could involve functions to get the current date and compare it with the selected date in the picker.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Disable Past/Future Dates:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Based on the comparison, disable click events or visually gray out dates that fall outside the current month.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;Here's a basic UI script example (modify it based on your specific UI framework):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Assuming 'datepicker' is the ID of the date picker element

function onChange() {
  var today = new Date();
  var selectedDate = datepicker.getValue();

  if (selectedDate.getMonth() != today.getMonth()) {
    datepicker.setDateRange(null, null); // Disable all dates
  }
}

datepicker.onChange = onChange;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This approach provides a more user-friendly experience by directly restricting clickable dates in the date picker.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&amp;nbsp;&lt;BR /&gt;Aravind Panchanathan&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 14:32:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856640#M5352</guid>
      <dc:creator>Aravind2799</dc:creator>
      <dc:date>2024-03-09T14:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856674#M5353</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/626621"&gt;@Rakesh_Damji&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had a similar requirement in past and had achieved it using onChange client script-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; var selectedDate = new GlideDateTime(newValue),
        beginningOfThisMonth = new GlideDateTime().setDay(1).setMonthUTC(selectedDate.getMonthUTC()).setYearUTC(selectedDate.getYearUTC()).setUTCHours(0).setUTCMinutes(0).setUTCSeconds(0).setUTCMilliseconds(0),
        endOfThisMonth = new GlideDateTime().setDayUTC(1).setMonthUTC(selectedDate.getMonthUTC() + 1).setYearUTC(selectedDate.getYearUTC()).setUTCHours(0).setUTCMinutes(0).setUTCSeconds(0).setUTCMilliseconds(0).subtract(1000);

    if (selectedDate.before(beginningOfThisMonth) || selectedDate.after(endOfThisMonth)) {
        g_form.addErrorMessage("You can only select dates within the current month.");
        g_form.setValue(control.name, oldValue);
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 09 Mar 2024 16:03:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856674#M5353</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2024-03-09T16:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856683#M5354</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/626621"&gt;@Rakesh_Damji&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Firstly, create a client script that validates the selected date and restricts it to the current month. it should trigger on &lt;STRONG&gt;both the onload and onchange events of the date picker field.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Within the script, validate whether the selected date falls within the current month.&lt;STRONG&gt; If it doesn't, display an error message prompting users to select a date within the current month.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attach this client script to the date picker field in the catalog request item form to enforce the desired restriction.&lt;/P&gt;&lt;P&gt;find the below client script below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    
    var selectedDate = new GlideDateTime(newValue);
    var currentDate = new GlideDateTime();

    if (selectedDate.getMonthOfYear() !== currentDate.getMonthOfYear()) {
        g_form.addErrorMessage('Please select a date within the current month.');
        g_form.clearValue(control.name);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this helps kindly accept the response thanks much&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Azar&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 16:30:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856683#M5354</guid>
      <dc:creator>Its_Azar</dc:creator>
      <dc:date>2024-03-09T16:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856742#M5363</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/626621"&gt;@Rakesh_Damji&lt;/a&gt;&amp;nbsp;, No code is Required for this we can Implement this Via UI Policy&amp;nbsp; , below I have added screenshot for your Reference&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="shyamkumarVK_0-1710011384720.png" style="width: 603px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/337518iBA7CD8F498894BCE/image-dimensions/603x257?v=v2" width="603" height="257" role="button" title="shyamkumarVK_0-1710011384720.png" alt="shyamkumarVK_0-1710011384720.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="shyamkumarVK_1-1710011457617.png" style="width: 590px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/337519iD15783B2EDE376F5/image-dimensions/590x290?v=v2" width="590" height="290" role="button" title="shyamkumarVK_1-1710011457617.png" alt="shyamkumarVK_1-1710011457617.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onCondition() {
    g_form.addInfoMessage("date cannot be selected in the past &amp;amp; Future")
    g_form.clearValue('date_validation');
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Shyamkumar&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 19:14:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856742#M5363</guid>
      <dc:creator>shyamkumar VK</dc:creator>
      <dc:date>2024-03-09T19:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856766#M5366</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Prohibiting date selection by removing dates before and after the current month is not doable without DOM manipulation, which is to be avoided.&lt;/P&gt;
&lt;P&gt;But you can easily implement a UI policy and UI policy action that clears the value if the user selects a invalid date.&lt;/P&gt;
&lt;P&gt;No code is required (or almost none depending on your needs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See example below.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ui-policy-this-month-only.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/337525i24DDB70C03C23CF3/image-size/large?v=v2&amp;amp;px=999" role="button" title="ui-policy-this-month-only.png" alt="ui-policy-this-month-only.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="ui-policy-action-this-month-only.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/337526i3F260C9CB9ABECB1/image-size/large?v=v2&amp;amp;px=999" role="button" title="ui-policy-action-this-month-only.png" alt="ui-policy-action-this-month-only.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 20:23:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2856766#M5366</guid>
      <dc:creator>OlaN</dc:creator>
      <dc:date>2024-03-09T20:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2862998#M5599</link>
      <description>&lt;P&gt;Thank you OlaN for your helpful suggestion. We are not yet on Washington (still on Utah), but were were able to implement your suggestions and they work great. Much appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 15:26:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2862998#M5599</guid>
      <dc:creator>Rakesh_Damji</dc:creator>
      <dc:date>2024-03-14T15:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2929037#M7643</link>
      <description>&lt;P&gt;am not getting option to add "Field Message"&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 04:27:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2929037#M7643</guid>
      <dc:creator>karan15</dc:creator>
      <dc:date>2024-05-14T04:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2935517#M7786</link>
      <description>&lt;P&gt;I believe this option was introduced in the Washington release.&lt;/P&gt;
&lt;P&gt;Have you upgraded yet?&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2024 19:39:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/2935517#M7786</guid>
      <dc:creator>OlaN</dc:creator>
      <dc:date>2024-05-18T19:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/3077093#M12098</link>
      <description>&lt;P&gt;How would i do this but for specific days of the week instead of month range?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 02:00:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/3077093#M12098</guid>
      <dc:creator>Julien Sanchez</dc:creator>
      <dc:date>2024-10-18T02:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to restrict the 'Date' variable in a catalog item to only allow only the current month click</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/3077095#M12099</link>
      <description>&lt;P&gt;Never Mind, the option for trends lets you select dates.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 02:08:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/how-to-restrict-the-date-variable-in-a-catalog-item-to-only/m-p/3077095#M12099</guid>
      <dc:creator>Julien Sanchez</dc:creator>
      <dc:date>2024-10-18T02:08:22Z</dc:date>
    </item>
  </channel>
</rss>

