UI Policy Not Working In Service Operations Workspace

tiguin2798
Tera Guru

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.

 

tiguin2798_0-1729114647771.png

Below is my UI Policy and the expected result in the default view:

tiguin2798_1-1729114709473.png

 

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');
}

 

tiguin2798_2-1729114798701.png



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?

tiguin2798_3-1729114945547.png

 

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);
    }
}

 




 

 

2 ACCEPTED SOLUTIONS

Tai Vu
Kilo Patron
Kilo Patron

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.

Timi_0-1729137320105.png

 

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

View solution in original post

tiguin2798
Tera Guru

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);
    }
}

 

View solution in original post

5 REPLIES 5

tiguin2798
Tera Guru

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);
    }
}