Past date alert UI policy

J_31
Kilo Sage

Hello,

If the user selects a past date in the when needed its must throw alert;

but when I select an old record which has an old date in the when field even it gets cleared I don't want to make any changes to the when_needed field for old records,even though the date is in the past.

Should I achieve this through UI or Client script - Please help?

I created a UI Policy as shown below and in the script tab I wrote:

alert('Please select future date');
g_form.clearValue('u_when_needed');

and condition is as shown below = When needed is the date field

 

I tried this is UI policy script:

but doesnt seem to work------>

function onCondition() {
/*
var ov = g_form.getValue('u_when_needed');
if (ov != "") {
g_form.setValue('u_when_needed',ov);
}*/
alert('Please select future date');
g_form.clearValue('u_when_needed');
}

 

find_real_file.png

 

 

1 ACCEPTED SOLUTION

Mahesh23
Mega Sage

Hi,

Try creating onChange() client script on "u_when_neede" field with below code

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below

var today = formatDate(new Date(),g_user_date_format);

if(g_form.isNewRecord() && newValue < today){

alert('Please select future date');
g_form.clearValue('u_when_needed');

} else {
alert('Please select future date');

}
}

 

View solution in original post

4 REPLIES 4

Mahesh23
Mega Sage

Hi,

Try creating onChange() client script on "u_when_neede" field with below code

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below

var today = formatDate(new Date(),g_user_date_format);

if(g_form.isNewRecord() && newValue < today){

alert('Please select future date');
g_form.clearValue('u_when_needed');

} else {
alert('Please select future date');

}
}

 

Many thanks ! it worked!

But have a question there is no date class in the client side API

where do you refer for such classes and methods like Date(), format date?

Mahesh23
Mega Sage

Hi,

Date() is a javascript date object. By default, JavaScript will use the browser's time zone and display a date as a full text string.

 

Refer below docs for better understanding 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

 

 

Please make my response as correct answer or helpful if applicable 

Excellent! Thanks a lot!