Reputation: 23
I am using a data transform to import a large .csv of emails into a Watchlist field. My .csv is in the following format:
"[email protected]", "[email protected], [email protected]",,"[email protected]"
I am using the following script to link the imported emails to User records, however my data transform ignores all records despite me manually confirming the emails exist, is there something wrong in this script?
answer = (function transformEntry(source) {
var grUsers = new GlideRecord('sys_user');
var users = String(source.u__users).split(",");
var query = 'email=LIKE' + String(users[0]);
var i = 1;
while(i != users.length){
query = query + '^ORemailLIKE' + String(users[i]);
i++;
}
grUsers.addEncodedQuery(query);
grUsers.query();
return grUsers.join(',');
})(source);
Upvotes: 1
Views: 494
Reputation: 4598
Two problems:
Here is an example based on your data:
var data = '"[email protected]","[email protected]","[email protected]","[email protected]"';
var users = String(data).split(",");
for (var i = 0; i < users.length; i++){
gs.print(users[i])
}
var query = 'email=LIKE' + String(users[0]);
gs.print(query);
Running this in Background Scripts I get:
*** Script: "[email protected]"
*** Script: "[email protected]"
*** Script: "[email protected]"
*** Script: "[email protected]"
*** Script: email=LIKE"[email protected]"
Here's the fixed one:
var data = '"[email protected]","[email protected]","[email protected]","[email protected]"';
var users = String(data).split(",");
for (var i = 0; i < users.length; i++){
users[i] = users[i].replace(/^"(.*)"$/, '$1');
}
for (var i = 0; i < users.length; i++){
gs.print(users[i])
}
var query = 'emailLIKE' + String(users[0]);
gs.print(query);
Result:
*** Script: [email protected]
*** Script: [email protected]
*** Script: [email protected]
*** Script: [email protected]
*** Script: [email protected]
Upvotes: 1