- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 05:08 AM
Requirement: Offboarding request catalog item have a date variable, it should always be a future date after atleast 2 weeks from the date of request submission.
Any help is greatly appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 02:31 AM
Hi @arjunchatla
You can try this onChange client script on your variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var date_number = getDateFromFormat(g_form.getValue('YOUR_VARIABLE_NAME'), g_user_date_format);
var selected_date = new Date(date_number);
var target_date = new Date();
target_date.setDate(target_date.getDate() + 13);
if(selected_date < target_date){
g_form.clearValue('YOUR_VARIABLE_NAME');
g_form.addErrorMessage("The selected date should be atleast after 14 days");
}
}
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 05:58 AM - edited 12-12-2023 06:31 AM
Hi @arjunchatla ,
Please try the below,
Script Include:
var checkDate = Class.create();
checkDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validDate: function (){
var chkDate = this.getParameter('sysparm_date');
var today_date = new Date();
var end_date = new Date(chkDate);
var diff = end_date.getTime() - today_date.getTime(); // timediff in milliseconds
var days = diff / (24 * 60 * 60 * 1000); //convert time into days
return days;
},
type: 'checkDate'
});
Catalog Client Script - onChange
var dt = newValue;
var checkCC = new GlideAjax('checkDate');
checkCC.addParam('sysparm_name', 'validDate');
checkCC.addParam('sysparm_date', dt);
checkCC.getXML(getCC);
function getCC(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if(answer < 14){
g_form.clearValue('<Variable name>');
g_form.showFieldMsg('<Variable name>', "Please select the date after 2 weeks.", 'error');
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Sujatha
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 02:31 AM
Hi @arjunchatla
You can try this onChange client script on your variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var date_number = getDateFromFormat(g_form.getValue('YOUR_VARIABLE_NAME'), g_user_date_format);
var selected_date = new Date(date_number);
var target_date = new Date();
target_date.setDate(target_date.getDate() + 13);
if(selected_date < target_date){
g_form.clearValue('YOUR_VARIABLE_NAME');
g_form.addErrorMessage("The selected date should be atleast after 14 days");
}
}
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 08:08 PM
Thanks Anvesh!
This worked like a charm!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 02:50 AM
Hi @arjunchatla
You can build an UI Policy with the Relative condition. Then just clear the field value if it match the condition (show msg if any).
Sample below.
Cheers,
Tai Vu