Email validation in on before script in transform map

Mr_Avinash
Kilo Expert

I need to validate the email. im trying to write on before script in a transform to validate email field and my target table is sys_user.In the source table the field is u_email.

1 ACCEPTED SOLUTION

You can use the email type field or variable which will automatically validate the email address 

or 

try this script :

var email = source.u_email;


if (!email || email.trim().length <= 0)


return true;


var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;


if (!re.test(email))

{

ignore =true;
}

else

{
ignore = false;
}

or you can follow this link :

https://community.servicenow.com/community?id=community_question&sys_id=83b88a49dbb7eb80feb1a851ca96...

mark my answer correct and helpful if it helps you !

regards,

apeksha

View solution in original post

8 REPLIES 8

Apeksha Joshi
Kilo Guru

Hi avinash ,

could you please elaborate the issue , is there any issue with the script ? or do you need some help with script ?

regards,

apeksha

Apeksha Joshi
Kilo Guru

Hi again ,

follow this link it will surely help you :

https://docs.servicenow.com/bundle/newyork-platform-administration/page/administer/import-sets/task/...

regards,

apeksha

Im trying the below script but it is not working

 

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

// Add your code here//Email validation

var errorFlag = false;
var email = source.u_email;
var errorMessage;
errorMessage = "Row("+(source.sys_import_row).toString() + ") ";

if(email.nil() || email == ""){
//do nothing
}
else if (!validateEmail(email)) {
errorMessage += "Please check Email ID format";
errorFlag = true;
}
// Email Validation Field
function validateEmail(field) {
var email = field;
if (!email || email.trim().length <= 0)
return true;
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!re.test(email)) {
return false;
}
return true;
}


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

You can use the email type field or variable which will automatically validate the email address 

or 

try this script :

var email = u_email;


if (!email || email.trim().length <= 0)


return true;


var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;


if (!re.test(email))

{

ignore =true;
}

else

{
ignore = false;
}

or you can follow this link :

https://community.servicenow.com/community?id=community_question&sys_id=83b88a49dbb7eb80feb1a851ca96...

mark my answer correct and helpful if it helps you !

regards,

apeksha