- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2024 02:48 PM - edited ‎10-16-2024 02:49 PM
Hey Everyone!
I have a requirement where on the 'change_request' table we want to have the 'start_date' and 'end_date' fields clear if the date is between a certain period and the 'state' is '-5' (for New). I created the following UI Policy which works fine in the default view with 'Global' checked, but not in the Service Operations Workspace view. As another user picking a date in this time in SOW nothing happens.
Below is my UI Policy and the expected result in the default view:
function onCondition() {
g_form.clearValue('start_date');
g_form.clearValue('end_date');
g_form.showFieldMsg('start_date', 'November 28th - November 29th is a blackout period. No changes may be scheduled during this time.)', 'error');
}
I saw another post that suggested converting this to an onChange client script for workspaces. Below is the client script I tried (with the UI Policy deactivated and UI type being 'All') and it still does not work in SOW view. I tried with g_sc_form instead of g_form as well. Can someone help me understand what I'm missing and need to change?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var state = g_form.getValue('state');
var blackoutStart = new GlideDateTime('2024-11-28 00:00:00');
var blackoutEnd = new GlideDateTime('2024-11-29 23:59:59');
var newValueDate = new GlideDateTime(newValue);
if (state == '-5' && newValueDate >= blackoutStart && newValueDate <= blackoutEnd) {
g_form.clearValue('start_date');
g_form.clearValue('end_date');
g_form.showFieldMsg('start_date', 'November 28th - November 29th is a blackout period. No changes may be scheduled during this time.', 'error');
} else {
g_form.hideFieldMsg('start_date', true);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2024 08:59 PM
Hey @tiguin2798
Regarding the UI Policy, let's double-check the "Run scripts in UI type" field. Make sure you’ve selected the All option to apply the UI Policy in workspace.
About your Client Script, the GlideDateTime object is for Server-side. So if you're trying to initialize it in a Client Script, that's likely you're encountering the undefined error.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2024 07:54 AM
All,
I figured out my issue with the client script. Per @Timi I removed the GlideDateTime objects and replaced with the Date object. Additionally, according to the article below I unchecked "isolate script" and the function is now working as intended in both SOW and Default views.
Thank you all for your help! Below is the corrected client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var state = g_form.getValue('state');
var blackoutStart = new Date('2024-11-28 00:00:00');
var blackoutEnd = new Date('2024-11-29 23:59:59');
var newValueDate = new Date(newValue);
if (state == '-5' && newValueDate >= blackoutStart && newValueDate <= blackoutEnd) {
g_form.clearValue('start_date');
g_form.clearValue('end_date');
g_form.showFieldMsg('start_date', 'November 28th - November 29th is a blackout period. No changes may be scheduled during this time.', 'error');
} else {
g_form.hideFieldMsg('start_date', true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2024 07:54 AM
All,
I figured out my issue with the client script. Per @Timi I removed the GlideDateTime objects and replaced with the Date object. Additionally, according to the article below I unchecked "isolate script" and the function is now working as intended in both SOW and Default views.
Thank you all for your help! Below is the corrected client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var state = g_form.getValue('state');
var blackoutStart = new Date('2024-11-28 00:00:00');
var blackoutEnd = new Date('2024-11-29 23:59:59');
var newValueDate = new Date(newValue);
if (state == '-5' && newValueDate >= blackoutStart && newValueDate <= blackoutEnd) {
g_form.clearValue('start_date');
g_form.clearValue('end_date');
g_form.showFieldMsg('start_date', 'November 28th - November 29th is a blackout period. No changes may be scheduled during this time.', 'error');
} else {
g_form.hideFieldMsg('start_date', true);
}
}