
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 04-11-2023 02:34 AM
Recently, came across an interesting question on the community Hide a specific HR service in Transfer Case here the questioner asked if a specific HR Service can be hidden within New HR Service dropdown when the person opts to transfer the case to some other COE.
Problem Statement:
Please refer to the following screenshots to get a glimpse of the problem statement.
The questioner wanted to remove some of the HR services from this list.
In order to answer this question, I did some preliminary research and asked him to make changes within Transfer case UI Page to get this job done.
He again inquired about the lines where the change was needed and in haste (my bad I should have been more careful) I pointed him in a direction which didn't yield any results.
He came back disappointed as the solution wasn't working for him. I felt bad for him and this time decided to give it a more closer look to solve the problem at hand.
Findings:
There is a section inside the Transfer case UI page which is responsible for populating this New HR Service dropdown.
If we look closely, we see a call to getServicesForUser method which is available inside hr_CaseCreation script include.
When I looked into this script include I found following.
This is an OOTB Script Include method which returns the HR Services for the subject person filtered by the HR Criteria.
First thought, which came to my mind was to ask the questioner to create an HR Criteria which will exclude the subject person from using that HR Services.
However, questioner wanted to exclude all the users in this case, another thought which crossed my mind to create an HR Criteria which will exclude all the users, however questioner wanted to exclude HR Services from Transfer Case operation only, he still wanted those HR services to be available for normal case creation.
This made me thinking as changes to OOTB script include method was out of equation due to the upgradability issues. Also, I wasn't sure where else this method is currently being used, or may be used in future by ServiceNow in their future releases, any changes here would have resulted in breaking some other functionality.
Good thing about the OOTB script include method is that the author not only provided a very good description of what method does, but also went an extra mile to share the skeleton of the object this method returns.
/*
@return Array of Objects,
* Example:
* [{
* display: String display value of Topic Category for HR Services,
* coe: COE for the service,
* children: Array of children HR Service objects
* Example:
* [{
* display: String display value of HR Service,
* sys_id: String sys_id of HR Service,
* coe: COE for the service,
* template: String sys_id of HR Service's template,
* parent: String Display value of HR Service's Topic Category
* }]
* }]
*/
This led me to create my own custom script include which filters the HR Services on top of the output generated by the OOTB script include method getServicesForUser which is available inside hr_CaseCreation script include.
Here is the source code of my custom 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'
};
Of course, we can create a comma separated string of HR Services and put it inside a system property which we can update externally without touching the code of the custom script include in future.
Once created we can use this script include inside Transfer case UI Page as follows.
Here on line number 30 the output of OOTB script include method has been passed to the custom script include which further filters the output and returns the filtered HR services.
Before: Here is how the interface looks before any HR services are excluded from the transfer case UI.
Here you can see, the HR Services HR Accounts Inquiry and Password Reset which are going to be excluded from this dropdown once we apply the filtaration.
After: This is how the dropdown looks when the aforementioned HR Services are excluded via the custom script include built for this purpose.
Hope this article helps someone who is trying to achieve similar functionality on their instance.
This is my first article on the community. Please feel free to point out the mistakes I made here, be it in terms of script or the overall approach I have taken to fix this problem.
Regards,
Sandeep
- 837 Views