transformation map to import user and create HR Profile

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2023 03:48 AM
Hi All,
I'm trying to update a transformation map on user table to create HR Profile in using onAfter script.
transformation map is in global scope (because I import on sys_user table)
No HR profile is created and I can find in the log "Source descriptor is empty while recording access for table sn_hr_core_profile: no thrown error"
Is this a problem with cross scoped access?
How can I solved this?
Thank you in advance.
(function runTransformScript(source, map, log, target /*undefined onStart*/) {
//Create HR profile if doesn't exist
var userId = target.sys_id;
checkAndCreateHRProfile(userId);
function checkAndCreateHRProfile(userId) {
var grHrProf = new GlideRecord('sn_hr_core_profile');
grHrProf.addQuery('user', userId);
grHrProf.query();
if (!grHrProf.next()) {
// grHrProf.setValue('user', userId);
// grHrProf.insert();
var hrProfile = new hr_Profile();
hrProfile.createProfileFromUser(userId);
}
}
})(source, map, log, target);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2023 08:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2023 10:28 AM
The rule is that objects created in a scope will have access to that scope. Thus if you could create a 2nd Transform map for your Input Row Set table in scope Human Resources: Core, whatever is executed in that Transform map (thus onAfter scripts too) would have access to the whole HR core scope.
Though in this case specifically, given that the Script Include is marked as callable from outside the HR core scope, one can just call it, but with the namespace prefix - as shown above.
In case of HR core scope this must be handled with care and such Script Includes - ones that enable reading or manipulating data from outside the HR core scope - should not be created: to prevent unauthorized HR data access.
In case of the Script Include you have used, it is acceptable as it does not expose any data and does not mess with existing data.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2023 02:48 PM
Please try to create this record for hr_Profile, or you can create one for HR profile table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2023 03:19 AM
When i tried to save, i receive an error message : Source scope can't be Global

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2023 07:49 AM
Hi all,
Thank you everyone for your help
Finally, It's work.
I use this script :
(function runTransformScript(source, map, log, target /*undefined onStart*/) {
//Create HR profile if doesn't exist
var userId = target.sys_id;
checkAndCreateHRProfile(userId);
function checkAndCreateHRProfile(userId) {
var grHrProf = new GlideRecord('sn_hr_core_profile');
grHrProf.addQuery('user', userId);
grHrProf.query();
if (!grHrProf.next()) {
grHrProf.setValue('user', userId);
grHrProf.insert();
}
}
})(source, map, log, target);
And I have created these 2 records