Hide a speciifc HR service in Transfer Case

Srinath S
Tera Contributor

Hi Everyone,

I want to hide a certain HR service in the Transfer Case, both in Native UI and HR Agent Workspace.

Any help is appreciated.

 

Thanks,

Srinath 

1 ACCEPTED SOLUTION

@Srinath S @Emi Nem 

Ah! my bad I forgot to share the solution for HR Agent Workspace. 

 

Caution: In order to achieve the same functionality on HR Agent workspace, you need to make some changes within an OOTB script include hr_CaseTransferAjax. Any changes here would mean you would need to take care of any changes during upgrades by manually merging them in this script include.

 

For now let's proceed with how this can be achieved in workspace.

 

When we closely look at the workspace client script for Transfer case UI Action we find the following.

Screenshot 2023-04-10 at 3.19.11 PM.png

This UI Action calls an OOTB script include hr_CaseTransferAjax to fetch the possible list of services. When we further drill down in this script include we find a method 

_getServices: function(subjectPerson) { on line number 44, which actually returns the list of services. 
 
This is actually the place where you need to make the changes.
Screenshot 2023-04-10 at 3.25.00 PM.png

On line number 45, replace the existing line with the following.

var oldServices = new sn_hr_core.hr_CaseCreation().getServicesForUser(subjectPerson || '', true);
var services = new sn_hr_core.HRServiceV2().getUpdatedHRServices(oldServices);

rest of the code should remain intact.

Screenshot 2023-04-10 at 3.08.37 PM.png

Save the changes and test it on workspace this time the excluded services will not appear.

 

This is how the service dropdown look when the "HR Accounts Inquiry" service is not exlcuded.

Screenshot 2023-04-10 at 3.07.23 PM.png

 

This is how it looks when it is excluded.

Screenshot 2023-04-10 at 3.12.14 PM.png

Hope finally this help you achieve your goal.

View solution in original post

12 REPLIES 12

Looks like the service list is being populated from some other section. Could you please revert the changes made earlier and restore the code back to the previous versions. 

 

Also, may I know on what basis you are going to hide the HR services will they be hidden for all or the visibility would be decided on the basis of subject person? I am sorry I should have asked this question earlier. 

Hi Sandeep,

I have to hide the HR service for all the users, not specific to anyone. If you have a look at the system property screenshot that I attached before, should we want to tie the system property to any category?  And also, there is no mistakes in the query that I have queried? Please let me know if something feels off about the customization I made for hiding the HR service.
Thanks,

Srinath

@Srinath S Thanks for sharing your inputs. Do you want these HR services just be excluded from transfer case drop down or do you want them to be unavailable for case creation from all the scenarios. Also, since my previous answer is misleading, I am deleting it from this thread. Will suggest another solution on the basis of your response.

Not HR services, I just want one HR service to be hidden. It should be available for case creation, I want to hide it only from transfer case's New HR service dropdown.

Sandeep Rajput
Tera Patron
Tera Patron

@Srinath S @Emi Nem 

 

Finally managed to crack the code for excluding specific HR Services from Transfer Case drop down. Initially, the code appeared simple, however when I started uncovering the layers I got to know about the underlying complexities.

 

Spent close to 2 hours last night to solve this mystery, in fact almost gave up it. However, found your messages today and thought of keep you waiting and then later on disappointing you made me give it another try and this time managed to do it :). Enough of talking let's get straight into the code.

 

First thing first, make sure to revert all the changes which you have done in Transfer case UI Page. My apologies for misguiding you earlier, I will try to be more careful in future before making such wild guesses. 

 

First of all create a script include which will the HR services for you. Here is the code for the script include.

var HRServiceV2 = Class.create();
HRServiceV2.prototype = {
    initialize: function() {},

    getUpdatedHRServices: function(services) {		
        var newServiceObjArray = [];
        var excludedServiceArray = ['5628cde49f331200d9011977677fcf04','d628cde49f331200d9011977677fcf03'];
									//HR Accounts Inquiry 5628cde49f331200d9011977677fcf04
									//Password Reset d628cde49f331200d9011977677fcf03
        for (var i = 0; i < services.length; i++) {
            var hrCOE = {};
            hrCOE['display'] = services[i].display;
            hrCOE['coe'] = services[i].coe;

            if (services[i].children) {
                var hrServiceArray = services[i]['children'];
                var newHRServiceArray = [];
                for (var j = 0; j < hrServiceArray.length; j++) {
                    if (excludedServiceArray.indexOf(hrServiceArray[j]['sys_id']) == -1) {
                        newHRServiceArray.push(hrServiceArray[j]);

                    } 
                }
                hrCOE['children'] = newHRServiceArray;
				hrCOE['sys_id'] = services[i].sys_id;
            } 
            newServiceObjArray.push(hrCOE);
        }		
		return newServiceObjArray;
    },
    type: 'HRServiceV2'
};

We will use this script include in the UI page to filter our hr services. In this example I am filtering two HR services //HR Accounts Inquiry 5628cde49f331200d9011977677fcf04 and //Password Reset d628cde49f331200d9011977677fcf03

 

You can define a property so that you wouldn't have to make changes in the script include time and again.

 

Here are the changes you need to do in your UI Page.

Screenshot 2023-04-08 at 10.06.22 AM.png

Here is the code 

<g:evaluate jelly="true">
var subjectPerson = jelly.sysparm_subject_person;
var services = new sn_hr_core.hr_CaseCreation().getServicesForUser(subjectPerson || '', true);
var newServices = new sn_hr_core.HRServiceV2().getUpdatedHRServices(services);			
var servicesString = JSON.stringify(newServices);							
</g:evaluate>

 

This is how Transfer case New service drop-down looks before excluding the HR services.

 

Before:

Screenshot 2023-04-08 at 9.50.01 AM.png

This is how the new service drop down look after applying the changes.

After:

Screenshot 2023-04-08 at 9.50.30 AM.png

Notice that HR Services  //HR Accounts Inquiry 5628cde49f331200d9011977677fcf04 and //Password Reset d628cde49f331200d9011977677fcf03 are no longer available for the Transfer Case operation. 

 

I am also attaching the UI Page, and Script include Source code for you. Please find them in the attachment.

 

Hope this helps 🙂