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

-O-
Kilo Patron
Kilo Patron

The message looks like a failed/not allowed cross-scope access.

A possible solution would be to move the code into a Script Include in scope HR core and mark it as callable from any scope. Though you need to be careful not to craft it so that it may leak profile info if used maliciously.

Another possibility might be to create a second Transform Map to be executed after the user one in scope HR core.

Finally, i used a business rule in Scope Human ressources Core when users is inserted, and it works.

 

I tried this code in on after script

(function runTransformScript(source, map, log, target /*undefined onStart*/) {


//Create HR profile if doesn't exist
var userId = target.sys_id;

var hrProfile = new hr_Profile();
hrProfile.createProfileFromUser(userId);

})(source, map, log, target);

hr_Profile is a script include OOB and callable from all Scope/

but it call the Global script named with the same name (legacy)

How i can call the Scoped script include?

 

When calling Script Includes from outside the current scope, one needs to use namespaces when creating an instance of the object defined in the Script Include; in your case:

var hrProfile = new sn_hr_core.hr_Profile();

The same thing that is contained in field API name of the Script Include record:

2023-01-22-1.jpg

 

John Zhang1
Kilo Patron
Kilo Patron

You may need to define the cross-scope app access.  Go System Application -->Application Cross-Scope Access