Create HR profile or update when user is inserted/Updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2022 11:48 PM
Hi Community,
I have created Business rule to auto create HR profile when the user record is inserted or updated if there is no HR profile created for the user. below is the business rule .but business rule is not working Can any one let me know if there are any changes in this code?
Business rule : After create/Update no conditions added in When to run and Actions. Just Added Advanced script
Thank you.
- Labels:
-
HR Service Delivery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 01:36 AM
Hello,
You should try and change:
gr.addQuery('user', user);
to
gr.addQuery('sys_id', user);
You also need to put your function and function call inside the
(function executeRule(current, previous /*null when async*/)
{
//function code
//call function
})(current, previous);
Also note that its bad practice to use gr as a object name for GlideRecords. A better name would be profileGR in this case. Although it probably wont affect you here, there are some situations in which gr can cause some complicated issues.
Let me know if the above change fixes the issue
If my answer has helped or resolved your query, please mark helpful/solved it based on impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 02:49 AM
Hi Dan,
Just one correction in the below code mentioned by you
Hello,
You should try and change:
gr.addQuery('user', user);
to
gr.addQuery('sys_id', user);
Highlighted line will not work as user is Gliding HR Profile table where normal reference to sys_user has the field name "User"
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
Regards,
Saurabh
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 02:01 AM
Change your complete business rule code as below
(function executeRule(current, previous /*null when async*/)
{
// Add your code here
checkAndCreatehrProfile(current.getUniqueValue());
function checkAndCreatehrProfile(user)
{
var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('user', user);
gr.query();
if (!gr.next())
{
var hrProfile = new hr_Profile();
hrProfile.createProfileFromuser(user);
}
}
})(current, previous);
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
Regards,
Saurabh
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 01:59 PM