Retrive requested_for department value to set a value on the ssp form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 10:07 AM
Hi All,
On the form there is one multiple choice field with options 'yes'/'no'
if that is 'yes' then retrieve the requested_for - department value based on that department value need to populate a default value on a field 'Lic'.
tried onChange script not helpful.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var dept = g_form.getValue('requested_for.department.name');
var rf = g_form.getValu('is_this_for_a_rf_user');
if (dept == "Manfacturing – ANZ" && rf == "yes") {
g_form.setValue('lic', 'Development LIC');
alert('test');
}
}
Any suggestions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 11:13 AM
Hi John,
You need to either do a getReference for the department or use a glideAjax and call a script include to get the value. Something like this:
var rf = g_form.getValue('is_this_for_a_rf_user');
var reqFor = g_form.getReference('requested_for', getDeptName);
function getDeptName(reqFor){
if (reqFor.department.name == 'Manfacturing – ANZ' && rf == 'yes'){
g_form.setValue('lic', 'Development LIC');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 11:49 AM
Hi @John1243 ,
You need to use glideAjax and script include for this, if you use getReference(), it's not gonna work because you'll only be able to dot walk till level 1.
Please use this client script and script include below
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var userGA = new GlideAjax('getUserDetails');
userGA.addParam('sysparm_name', 'getDepartment');
userGA.addParam('sysparm_user', g_form.getValue('requested_for'));
userGA.getXMLAnswer(_handleResponse);
function _handleResponse(answer) {
var rf = g_form.getValue('is_tis_for_a_rf_user');
if (answer == "Manfacturing – ANZ" && rf == "yes") {
g_form.setValue('lic', 'Development LIC');
}
}
}
Script Include:
var getUserDetails = Class.create();
getUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDepartment : function(){
var user = this.getParameter('sysparm_user');
var userGR = new GlideRecord('sys_user');
userGR.get(user);
var dept = userGR.department.name;
return dept;
},
type: 'getUserDetails'
});
If my answer has helped with your question, please mark it as helpful and accepted solution.
Thanks,
Karan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 12:33 PM
the above scripts are not working in my case.
we are having a variable set in that we are having all the requested for related fields like manager, email, department , etc and we are auto populating all the details through script include & onchange script
we are not displaying all the fields on the ssp form only requested_for field will be displayed and remaining all fields will be only be displayed on the RITM.
so in my current requirement will this work of retrieving the department and adding condition to it.
Any suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 12:39 PM
@John1243 - the above script should work fine, i tested it on my PDI as well, please check the variable and choice backend names.