- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 12:04 PM
Hello, I am working on a Record Producer that will be assigned as a task to the manager to verify user Information.
I want the Record Producer to populate the Subject person information instead of the manager information. I am trying to implement a script that will populate the Subject person fields but I am having issue finding the specific way to reference the HR case that will have the subject person SysID to get their information. I have a variable called hr_case referencing the Hr Case Table. I am using that variable in the script to reach the subjectPerson SysID. I get a blank without the sysid. have attached screenshots.
Please assist.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 07:17 AM
@mlamin I have been in the similar situation in the past and found a rather crude way to fetch subject person's detail on an HR Task. You can use the same approach if you want to.
Problem Statement: Fetching the details of a subject person on an HR Task of type Submit Catalog Item.
Solution: Unfortunately, there is no direct way to fetch the sys_id of subject person on HR Task, if we closely look at the page source on my Todos page, there is no way we can get details like parent HR Case or any subject person related information. Even there is no direct way to know about the sys_id of the current HR task.
After going through the page source, I spotted an HTML div where the task's sys_id is available in an abstract manner.
Searched on the backend using this sys_id and found the corresponding HR task.
Since HR task has a parent HR Case, hence subject person related details can be fetched easily from it.
Now the question of pulling this abstract hr task sys_id in a client script came. Here, I simply applied some javascript to fetch the intended information.
Using this info: Simply used added a reference variable HR Task on the Record producer.
Used the following Onload script to populate my HR Task reference field.
Here is the script for the same.
function onLoad() {
//Type appropriate comment here, and begin script below
//Following line fetches the sys_id of the task shown in To-Dos
var hrTaskSysID = this.document.getElementsByClassName('task-content')[1].id.split('_')[0];
g_form.setValue('hr_task',hrTaskSysID);
}
Added another variables to get details related to the subject person.
Added couple of more single line text variables for representing First name and last name
Here is the client script I used to populate these variables.
Here is the client script.
Here is the source of client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var myUtils = new GlideAjax('HRUtils');
myUtils.addParam('sysparm_name', 'getSubjectPersonForHRTask');
myUtils.addParam('sysparm_hr_sys_id', g_form.getValue('hr_task'));
myUtils.getXML(subjectPersonResponse);
function subjectPersonResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var subjectPerson = JSON.parse(answer);
g_form.setValue('subject_person', subjectPerson['subject_person_sys_id']);
g_form.setValue('first_name', subjectPerson['subject_person_first_name']);
g_form.setValue('last_name', subjectPerson['subject_person_last_name']);
}
}
Now comes the script include.
var HRUtils = Class.create();
HRUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSubjectPersonForHRTask: function() {
var hrTaskSys_id = this.getParameter('sysparm_hr_sys_id');
var glideHRTask = new GlideRecord('sn_hr_core_task');
var subjectPerson = {};
if (glideHRTask.get(hrTaskSys_id)) {
subjectPerson['subject_person_sys_id'] = glideHRTask.parent.subject_person.getValue('sys_id');
var glideUser = new GlideRecord('sys_user');
if (glideUser.get(glideHRTask.parent.subject_person.getValue('sys_id'))) {
subjectPerson['subject_person_first_name'] = glideUser.getValue('first_name');
subjectPerson['subject_person_last_name'] = glideUser.getValue('last_name');
}
}
return JSON.stringify(subjectPerson);
},
type: 'HRUtils'
});
Here is the end result. Here all the details have been fetched dynamically using the solution shared above.
Many would argue that we should not reply on the HTML task-content class as it may change in the future versions but this is the risk I am willing to take as long as it gets me the desired results.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 12:15 PM
You can't dot-walk in a getValue, so you'd have to do a getReference on the hr_case to get the subject person
When this script runs onLoad of the Record Producer form, is the HR Case populated? If not, change it to onChange when Hr Case changes.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 12:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 07:02 AM
@michaelj_sherid Thank you for the response, I was able to follow the documentation to create an LE Activity with flow. I am having an issue linking those mapping fields to the record producer. I have the record producer as an HR Task in the flow. Please see the screenshot.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:04 AM
@mlamin You do not have to use a flow action, that is just another way to leverage the mapping. You just have to open the Activity that has the Submit Catalog Item as the HR Template then just map to the variable question as you see below:
Regards,
Mike