Date Validation while importing

ar1
Kilo Sage

Hi All,
Can anyone please help on the below requirement.

We have below three fields on custom table level and while importing we need to check like

1. If the Date type field data entered as MM:DD:Year instead of DD:MM: Year then we need to auto check the Error checkbox field.
2. If the String field value entered as Alpha numeric values then we need to check the Error checkbox field.

Table fields:
1. Date ---> Date type
2. Description ----> String type
3. Error ----> Checkbox type

Advance thanks

1 ACCEPTED SOLUTION

Hi,

then something like this

Use regular expression for the date format validation and Alpha numeric

I assume you are comfortable in using RegEx in ServiceNow. If not you will find many examples on community and other blogs

https://www.codegrepper.com/code-examples/javascript/regex+for+date+mm%2Fdd%2Fyyyy

Regular Expression for alphanumeric and underscores

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here

	var date = source.u_date;
	var description = source.u_description;

	// use regular expression to validate date format
	if(<regex is not satisfied || regex of alphanumeric is not satisfied>)
		target.u_error = true;

})(source, map, log, target);

Regards
Ankur

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

View solution in original post

9 REPLIES 9

Hi,

which fields from import set you want to validate?

Regards
Ankur

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

Hi Ankur,
Thanks for the response.

"Date" -----> Type Date field
And
"Description" ---> Type String field.

We need to set the Error checkbox field as True.

Thanks.

Hi,

you are talking about target field then which fields are present in the import set?

Regards
Ankur

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

Hi,
In excel also same fields are available.

Date and Description.

 

Hi,

then something like this

Use regular expression for the date format validation and Alpha numeric

I assume you are comfortable in using RegEx in ServiceNow. If not you will find many examples on community and other blogs

https://www.codegrepper.com/code-examples/javascript/regex+for+date+mm%2Fdd%2Fyyyy

Regular Expression for alphanumeric and underscores

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here

	var date = source.u_date;
	var description = source.u_description;

	// use regular expression to validate date format
	if(<regex is not satisfied || regex of alphanumeric is not satisfied>)
		target.u_error = true;

})(source, map, log, target);

Regards
Ankur

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