HRSD: updating opened_for in agent workspace

beckerlt
Tera Contributor

Hello,

 

I am working on a project that involves making a UI button visible in the agent workspace based on a field in the hr_profile. During this implementation, I discovered that our opened_for does not always align with our hr_profile.

 

I found some relevant Business Rules that populate these fields (which I believe are OOB)

 

You will see that there is a business rule that updates the subject_person_hr_profile whenever the subject person changes. But the Business rules for hr_profile either set the opened_for based on the hr_profile OR set the hr_profile based on the opened_for.

 

In HR Agent Workspace we do not have an OOB field visible for agents to change the hr_profile. They do however, change the opened_for rather frequently. I looked in our audit table in our production instance and found that the opened_for changes after case creation hundreds of times per year. That means for all of those cases the opened_for and the hr_profile is out of sync.

 

Which is the best approach to resolve this inconsistency? Should I update the BRs to mimic the way the subject_person populates the hr_profile. Or should I surface the hr_profile field in the Agent workspace and make the opened_for read only so the agent has to change the hr_profile directly?

 

1) Populate profile
Before | Order 100 | Insert and Update

Condition: !current.opened_for.nil() && current.hr_profile.nil()
Script:

(function executeRule(current, previous /*null when async*/) {
    var profileGr = new GlideRecord("sn_hr_core_profile");
    profileGr.addQuery("user", current.opened_for);
    profileGr.query();
    if (profileGr.next())
        current.hr_profile = profileGr.getUniqueValue();
})(current, previous);
2) Set opened_for based opened_for_profile
Before | Order 100 | Update

Condition: current.hr_profile.changes()
Script: 

var grProfile = new GlideRecord('sn_hr_core_profile');

if (grProfile.get(current.hr_profile)) {
    var grUser = new GlideRecord('sys_user');
    if (grUser.get(grProfile.user))
        current.setValue('opened_for', grUser.sys_id);
}
 
3) Populate HR Profile For Subject Person
Before | Order 100 | Insert & Update
Condition:  current.subject_person.changes()
Script:
(function executeRule(current, previous /*null when async*/) {
    if (gs.nil(current.subject_person))
        current.subject_person_hr_profile = "";
    else {
        var hrProfile = new GlideRecord('sn_hr_core_profile');
        hrProfile.addQuery('user', current.subject_person);
        hrProfile.query();
        if (hrProfile.next())
            current.subject_person_hr_profile = hrProfile.getUniqueValue();
    }
})(current, previous);
0 REPLIES 0