- 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-16-2024 03:40 PM
Hi,
Have you checked if the Run scripts in UI type option in your UI Policy is set to "All"? When I recreated your UI Policy, it worked as expected when this was set to "All." However, if it's left at the default setting of "Desktop," the script doesn't seem to run in the workspace.
If this resolves your issue, please mark the answer as "Helpful" or "Correct."
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2024 06:23 AM - edited ‎10-17-2024 06:32 AM
Hello,
Yes, the UI type in my UI Policy is set to "All" and "Global" is checked. I tried it with removing the state field, but that did not change anything for existing change request or when creating a new one. Do you mind me asking what is different in your UI Policy that worked?
I did create a new change after this and where it does nothing in the SOW view still. It does clear the dates I entered in the default view.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2024 07:37 PM
@tiguin2798 Try running the UI Policy without any conditions and see if it triggers, if it works see if the date format in the condition is causing any issues.
- 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