How to sync between user records and hr profiles after a user record is updated from LDAP?

jordanh
Giga Contributor

We have added a new field to the user table that we also want to sync with the HR profile. I found in the hr_Utils script include where the map is that determines which fields to sync between the two but now I am having difficulties getting it to execute. I tested a script to find all the HR profiles linked to active users and then call the same method that the sync user record to hr profile business rule calls "new hr_Profile(userRec, gs).syncProfileFields()" and nothing happens. When I run a background script to change the value of the field we are attempting to sync it works though. Was hoping someone who has some experience in this area could provide some insight on how to add data to either the hr profile or user records and then sync the additional fields.

1 ACCEPTED SOLUTION

jordanh
Giga Contributor

Okay, so I was able to get the major issue I was dealing with resolved by copying and modifying one of the existing functions in the hr_Utils script include. The function syncProfileWithUser will do a one way sync from the HR Profile to the associated user record by calling the syncProfilesWithMap function which takes as parameters the source record, the destination record, a field map object presumably for fields not named the same, an array of fields to exclude and the last parameter which is a boolean and tells it whether to update the values on the destination record even if the values on the source record have not changed or to only update field values that have changed. I copied this function and named it syncUserWithProfile and swapped which record it passes as the source and destination when calling the syncProfilesWithMap function so that the user record is used as the source and the profile as the destination. I'll just need to trigger an event now to run this after a user record is changed by the LDAP import to ensure the info is sync'd.


View solution in original post

5 REPLIES 5

sachinbhasin11
Tera Guru
Tera Guru

Hi Jordan,



Why do you want to call a script to sync the records between two records, this functionality is available OoB, can you please specify your business requirement here.



You can generate HR Profiles by using 'Generate HR Profile' module available OoB


We are using the non-scoped HR app which doesn't have the generate HR profiles module, and requires them to be created manually (at least OOB). The particular issue I was having is that I have a data point that comes in via an LDAP import from AD which doesn't trigger business rules to run and so that data point isn't being sync'd to the user's HR Profile. I found the issue with my original script which is that the method that the business rule calls requires that the value has changed, which in my case it hasn't because it was previously set by the LDAP import.


Joe Dames
Tera Expert

Can you post your scripts? I've found watching logtail is useful when testing cross scope permission issues:



"https://YOURINSTANCENAME.service-now.com/channel.do?sysparm_channel=logtail"


jordanh
Giga Contributor

Okay, so I was able to get the major issue I was dealing with resolved by copying and modifying one of the existing functions in the hr_Utils script include. The function syncProfileWithUser will do a one way sync from the HR Profile to the associated user record by calling the syncProfilesWithMap function which takes as parameters the source record, the destination record, a field map object presumably for fields not named the same, an array of fields to exclude and the last parameter which is a boolean and tells it whether to update the values on the destination record even if the values on the source record have not changed or to only update field values that have changed. I copied this function and named it syncUserWithProfile and swapped which record it passes as the source and destination when calling the syncProfilesWithMap function so that the user record is used as the source and the profile as the destination. I'll just need to trigger an event now to run this after a user record is changed by the LDAP import to ensure the info is sync'd.