- 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-03-2023 08:10 AM
@michaelj_sherid Thanks for the clarification Michaelj, I was under the impression that this mapping only works with Flow type activities.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:59 AM
@michaelj_sherid Apologies, I am a little confused about what you are referring to.
- I don't need to create a flow action, then what will the flow have within it?
- I have an activity that has the that is a type flow, is that not supposed to be that?
- Are there 2 activity I am supposed to have?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 09:05 AM
@mlamin You do not need to use flow. You can open the activity for the "Submit Catalog Item". At the bottom of the activity you can map the subject person of the parent LE Case to the question within the Catalog Item (Variable). The catalog item would need a question something like "Who is this request for" to which you would use the activity field mapping (at the bottom of the Activity as shown in my last image I included). This is a configurable way to map data from the parent case to a question within the Catalog Item.
Regards,
Mike

- 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-23-2023 11:10 AM
Hello, thank you, I was able to use this to solve my issue. With some changes like having all in the same scope, and editing script to fit my specific need. Thank you so much again!