- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 10:28 AM
Hi,
I need help with auto populating the department field on the sc_task form.
I've created a new departmeent field (u_department_task) but would like it to be pulling the data from the Requested For field (requested_for)
Client script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:49 PM
Hello @Kiet1 ,
Please Replace your script with below script:-
Client Script:-
function onLoad() {
//Type appropriate comment here, and begin script below
var req= g_form.getValue('request_item');
var ga = new GlideAjax('departmentDetail');
ga.addParam('sysparm_name', 'getDetails');
ga.addParam('sysparm_req', req); //newValue will requester for
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_department_task', answer); // enter correct variable name here
}
}
Script include:-
var departmentDetail = Class.create();
departmentDetail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var req = this.getParameter('sysparm_req');
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', req);
gr.query();
if (gr.next()) {
return gr.request.requested_for.department.toString();
}
},
type: 'departmentDetail'
});
Please Mark my answers Helpful & Accepted if I have answered your questions.
Thanks,
Alka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 11:58 AM
Thanks Sandeep but it dosen't work 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:03 PM
@Kiet1 Did you clear the cache, sometime previous client scripts are cached and hence the new changes don't reflect use ctrl+R for hard refresh.
function onLoad() {
//Type appropriate comment here, and begin script below
var user = g_form.getReference('request_item.requested_for', callBack);
function callBack(user) {
alert(user.department);
g_form.setValue('u_department_task', user.department);
}
}
Let me know if you manage to see the alert.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:06 PM
This is what I see when I execute my script, it manages to fetch the department id of the requestor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:13 PM
@Kiet1 Change you client script to on load and try the @Sandeep Rajput script. Then, your requirement will be fulfilled.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:24 PM
@Alka_Chaudhary Thanks for endorsing my reply. May be due to caching Kiet is not able to see changes made by my script.