We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

restirction due date is not working in SOW view

Sriram Pusuluri
Tera Contributor

Hi,

 

I have written onchange client script, below is my script

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '')
        return;

    if (newValue == oldValue)
        return;

    var format = g_user_date_time_format; // or g_user_date_format
    var dateMs = getDateFromFormat(newValue, format);

    var selectedDate = new Date(dateMs);
    selectedDate.setHours(0,0,0,0);

    var today = new Date();
    today.setHours(0,0,0,0);

    if (selectedDate < today) {

        g_form.clearValue('due_date');

        setTimeout(function() {
            g_form.showFieldMsg(
                'due_date',
                'Past dates are not allowed. Please select Today or Future.',
                'error'
            );
        }, 100);

    } else {
        g_form.hideFieldMsg('due_date');
    }
}

 

Code is working fine in Native view, when I am working on SOW it is not working.  

 

Field is due_date and Type is Date/Time

1 ACCEPTED SOLUTION

@Sriram Pusuluri 

this UI policy worked for me in both

Even if you give 1 min in past it gives error

AnkurBawiskar_0-1771224728071.pngAnkurBawiskar_1-1771224737800.png

Output

due date not in past 1 min also not working.gif

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

@Ankur Bawiskar 

 

I have created new UI Policy, It is working fine

 

I have query here:

I have entered Due Date as 16/02/2026 07:09:22, After saving this it is allowed me , working fine.

 

Now After 2 minutes if I come to same Problem record, it is showing error message.

 

what can I do here?

@Sriram Pusuluri 

Glad to know that my approach worked

uncheck the onLoad checkbox for your UI policy

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

@Sriram Pusuluri 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Manolis Sgouro1
Tera Contributor

Hello @Sriram Pusuluri ,

 

The solution proposed by @Ankur Bawiskar looks better.

But for your script you mention, can you please verify if the UI Type of the script is set to "All"?

Screenshot 2026-02-16 083649.png