offboarding validation

arjunchatla
Mega Contributor

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!

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

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 👍✔️

  

Thanks,
Anvesh

View solution in original post

7 REPLIES 7

Sujatha V M
Kilo Patron
Kilo Patron

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

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

AnveshKumar M
Tera Sage
Tera Sage

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 👍✔️

  

Thanks,
Anvesh

Thanks Anvesh!

This worked like a charm!

Tai Vu
Kilo Patron
Kilo Patron

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.

Timi_0-1702464620032.png

 

Cheers,

Tai Vu