transformation map to import user and create HR Profile

Dimitri Destin
Tera Guru

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);




13 REPLIES 13

Cross -Scope access is a new concept for me. I have no idea what I need to create to allow an onAfter script of a transformation map (Global) to query the HR profile table

What I have to enter here? 

thank you for your help

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.

Please try to create this record for hr_Profile, or you can create one for HR profile table

JohnZhang1_0-1674427548306.png

    

When i tried to save, i receive an error message : Source scope can't be Global

Dimitri Destin
Tera Guru

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

2023-01-26_16h48_35.png