Need help for one of Transform script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 03:25 AM
Hi Everyone,
I am facing below issue for one of the transform map.
we have active and inactive users in User table.
The Username is mapping to inactive id of user record instead of active user.
We have a Datasource of Excel we need load data to our Target Table.
Source table : Users details table(imp_user_details)
Target Table : Users table(sys_user)
Field maps:
source field | target field | coalesce |
using script | active | true |
u_user_name | stu_user_name | false |
u_email | true | |
u_user_id | stu_user_id | false |
In my source field script :
answer = (function transformEntry(source) {
return true;
})(source);
now i am facing issue as the user name was tagging to inactive user instead of active users.
I am not understanding what is the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 03:33 AM
as per your field map you have marked 2 fields as coalesce
If either value is not found, it will go ahead and create
Do you want to create users or update users?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 03:53 AM - edited 04-19-2024 04:00 AM
1. I need to update user with User name . I dont want to create any.
2. it need to update Stu User name only for active users
The below is before tranform script where i was restricting insert action
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
if (action == 'insert') {
log.error("User do not exist");
ignore = true;
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 04:29 AM
then handle this using onBefore transform script only and remove all field maps but keep field map only for email with coalesce=true
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
if (action == 'insert') {
log.error("User do not exist");
ignore = true;
}
if(target.active == true && action == 'update'){
target.stu_user_id = source.u_user_id;
target.stu_user_name = source.u_user_name;
}
})(source, map, log, target);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 03:38 AM
reurn 'true'