- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 06:32 AM
Hi All,
I have written below Trasform map code to update multiple users on contributor field. but some how it is allowing only one user to update.
While loading the data throwing following warning message Contributor abc@ doesn't exist in ServiceNow . but user is available and active in servicenow
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 12:09 AM
Hi @Venkataramudu A
Ensure there are no extra spaces in the email addresses. also the "Contributor" field is of type string or array that can handle multiple values correctly.
Use join(',') for proper formatting of multiple sys_ids.
answer = (function transformEntry(source) {
var contributors = [];
var con_email = source.u_contributors.split(',').map(function(email) { return email.trim(); });
if (source.u_contributors) {
for (var j = 0; j < con_email.length; j++) {
var gr_user1 = new GlideRecord('sys_user');
gr_user1.addQuery('email', con_email[j]);
gr_user1.query();
if (gr_user1.next()) {
contributors.push(gr_user1.sys_id);
} else {
gs.warn("Contributor " + con_email[j] + " doesn't exist in ServiceNow for policy " + source.u_name);
}
}
var contributors1 = contributors.join(',');
return contributors1;
} else {
gs.warn("Contributors are not defined for " + source.u_name + " policy");
}
})(source);
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 12:09 AM
Hi @Venkataramudu A
Ensure there are no extra spaces in the email addresses. also the "Contributor" field is of type string or array that can handle multiple values correctly.
Use join(',') for proper formatting of multiple sys_ids.
answer = (function transformEntry(source) {
var contributors = [];
var con_email = source.u_contributors.split(',').map(function(email) { return email.trim(); });
if (source.u_contributors) {
for (var j = 0; j < con_email.length; j++) {
var gr_user1 = new GlideRecord('sys_user');
gr_user1.addQuery('email', con_email[j]);
gr_user1.query();
if (gr_user1.next()) {
contributors.push(gr_user1.sys_id);
} else {
gs.warn("Contributor " + con_email[j] + " doesn't exist in ServiceNow for policy " + source.u_name);
}
}
var contributors1 = contributors.join(',');
return contributors1;
} else {
gs.warn("Contributors are not defined for " + source.u_name + " policy");
}
})(source);
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 12:20 AM
Hi @Venkataramudu A ,
Try changing the line "contributors.push(gr_user1.sys_id);" as below,
contributors.push(gr_user1.getValue('sys_id'); or contributors.push(gr_user1.sys_id.toString();
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang