Auto population of reference variable doesn't give correct result
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2024 04:13 AM - edited ‎04-15-2024 04:17 AM
Hi ,
I am trying to auto-populate the fields (Manager, Manager's manager ,title) based on the username from the user table. When I am opening the catalog item, the primary owner(manager) and secondary owner name shows the correct results but when the form is submitted the secondary owner name(manager's manager name) is showing on both primary owner and secondary owner field. the primary owners name is not getting captured post form submission.
Could you please help where I am doing wrong:
Below is the script I am using :
Script Include :
var ServiceAccountUserDetails = Class.create();
ServiceAccountUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userdetails: function() {
var userObj = {};
var input = this.getParameter('sysparm_userSelected');
var gr = new GlideRecord('sys_user');
if (gr.get(input)) {
userObj.grtitle = gr.title.getDisplayValue();
userObj.grprimarymanager = gr.manager.sys_id.getDisplayValue();
userObj.grmanager2 = gr.manager.manager.sys_id.getDisplayValue();
}
return JSON.stringify(userObj);
},
type: 'ServiceAccountUserDetails'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var srvusrname = g_form.getValue('provide_the_service_account_user_name');
var ops = new GlideAjax('ServiceAccountUserDetails');
ops.addParam('sysparm_name', 'userdetails');
ops.addParam('sysparm_userSelected', srvusrname);
ops.getXMLAnswer(function(response) {
{
var userObj = JSON.parse(response);
g_form.setValue('title_mod_del', userObj.grtitle);
g_form.setValue('primary_owner_mod_del', userObj.grprimarymanager);
g_form.setValue('secondary_owner_mod_del', userObj.grmanager2);
}
});
}
Thanks.
0 REPLIES 0