variable set info to autofill variable in schema
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 05:08 AM
Hello
i got a variable set in my schema named "employee info"
in this set i got "employee_name" and "employee_id"
When a name is selected it auto fills in the ID. i got a variable in my schema that is "employee_department".
How do i make it so when i select a user name in the field thats in the variable set, it also auto fill out the variable in the schema?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 07:09 AM
From what UI understand it seems like you have variables "employee_name" and "employee_id" in Variable set and "employee_department" outside variable set on the item variable list. Considering you are populating the "employee_id" from"employee_name" using Auto-populate tab on the employee_id variable as shown below.
To populate the department field which is outside the variable set either you can move the variable into the variable set and use this same method or you will have to use the AJAX.
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var id = g_form.getValue('emp_name'); //from the variable set
var ga = new GlideAjax('sampleUtils'); //Scriptinclude
ga.addParam('sysparm_name', 'getUserDetails'); //Method
ga.addParam('sysparm_userId', id); //Parameters- sys id of the user
ga.getXMLAnswer(getResponse);
function getResponse(response) {
g_form.setValue('emp_dept', response);
}
}
Script Include:
(make sure to check the client callable true)
var sampleUtils = Class.create();
sampleUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var userId = this.getParameter('sysparm_userId'); //sys id of user
var deptt;
var gr = new GlideRecord('sys_user');
gr.get(userId);
deptt = gr.department.name; //dot walk department name
if (deptt) {
return deptt;
} else
return '';
},
type: 'sampleUtils'
});
If this response clears up your doubt, kindly flag it as both helpful and correct.
Thanks