Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

transform script error

Deepthi13
Tera Expert

please correct this code, i am getting empty watchlist

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var watchList = [];
var activeEmail = source.u_data_identify_active_email_;
var nonEmail = source.u_data_identif_ive_non_email_;
var email = source.u_data_identify_email_;
gs.info("@@@ "+activeEmail+"    "+nonEmail+"        "+email);
if(activeEmail == true){
    watchList.push("2fe56c168796e1d01436877d0ebb352d");//Active Email- 2fe56c168796e1d01436877d0ebb352d
}
else if(nonEmail == true){
    watchList.push("509032d647131518ec2ae757436d432a");//Non Email- 509032d647131518ec2ae757436d432a
}
else if(email == true){
    watchList.push("2fe56c168796e1d01436877d0ebb352d");//Email- 5fcfe2da47131518ec2ae757436d433f
}
target.u_identify_data_media = watchList;
gs.info("@@@1 "+watchList);

})(source, map, log, target);
1 ACCEPTED SOLUTION

SanjivMeher
Mega Patron
Mega Patron

You should stringify the array like watchList.toString() to set a list field. I would also suggest not hard coding with sysids.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var watchList = [];
var activeEmail = source.u_data_identify_active_email_;
var nonEmail = source.u_data_identif_ive_non_email_;
var email = source.u_data_identify_email_;
gs.info("@@@ "+activeEmail+"    "+nonEmail+"        "+email);
if(activeEmail == true){
    watchList.push("2fe56c168796e1d01436877d0ebb352d");//Active Email- 2fe56c168796e1d01436877d0ebb352d
}
else if(nonEmail == true){
    watchList.push("509032d647131518ec2ae757436d432a");//Non Email- 509032d647131518ec2ae757436d432a
}
else if(email == true){
    watchList.push("2fe56c168796e1d01436877d0ebb352d");//Email- 5fcfe2da47131518ec2ae757436d433f
}
target.u_identify_data_media = watchList.toString();
gs.info("@@@1 "+watchList);

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

You  


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

SanjivMeher
Mega Patron
Mega Patron

You should stringify the array like watchList.toString() to set a list field. I would also suggest not hard coding with sysids.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var watchList = [];
var activeEmail = source.u_data_identify_active_email_;
var nonEmail = source.u_data_identif_ive_non_email_;
var email = source.u_data_identify_email_;
gs.info("@@@ "+activeEmail+"    "+nonEmail+"        "+email);
if(activeEmail == true){
    watchList.push("2fe56c168796e1d01436877d0ebb352d");//Active Email- 2fe56c168796e1d01436877d0ebb352d
}
else if(nonEmail == true){
    watchList.push("509032d647131518ec2ae757436d432a");//Non Email- 509032d647131518ec2ae757436d432a
}
else if(email == true){
    watchList.push("2fe56c168796e1d01436877d0ebb352d");//Email- 5fcfe2da47131518ec2ae757436d433f
}
target.u_identify_data_media = watchList.toString();
gs.info("@@@1 "+watchList);

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

You  


Please mark this response as correct or helpful if it assisted you with your question.

got solved by just giving 

watchList.toString(","); at end. thanks.