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

Hi @Tai Vu 

Thanks for your answer, but it didn't work for me. May be I did something wrong.

Hi @arjunchatla 

Oops! I see. The validation is "always be a future date after at least 2 weeks from the date of request submission."

So the condition above from my screenshot should be Before (Not After).

 

Cheers,

Tai Vu

matthewzahrt
Giga Contributor

Matt from ReadyCloud here,

 

This is a great approach for enforcing offboarding timelines in ServiceNow. We actually have an app in the ServiceNow Store that automates the entire device return process and plugs directly into your existing offboarding workflows. Instead of the traditional "ship a box and wait", the offboarded employee receives a QR code via email or text and simply drops off their gear at the UPS. The app also handles automated follow-up, cutting shipping time in half, reducing time spent on chasing gear, and significantly improving return rates. Let me know if you have any questions.