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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So you would require onbefore transform script for this

What did you start with and where are you stuck?

Regards
Ankur

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

Hi Ankur,
Many thanks for the response.
 We tried few possibilities but no luck. 
And We are new to Transform scripts.
Could you pls provide us the sample script.


And also instead of Transform scripts, Is there any way to achieve this ???

Because some times end user directly import the on custom table level.


Many thanks.

Hi,

since you mentioned while importing you can use before insert BR as well on that table

Regards
Ankur

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

Hi Ankur,
Many thanks for the reply.
Okay, will work around on Business rule logic.
Could you please provide the sample script for Transform Script logic.

Advance thanks.