Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Type: Catalog Client Script
// Applies to: 'user' field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setValue('manager', '');
return;
}

var ga = new GlideAjax('GetManager');
ga.addParam('sysparm_name', 'getManager');
ga.addParam('sysparm_user_id', newValue);
ga.getXMLAnswer(function(response) {
g_form.setValue('manager', response);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Auto-Populate Manager Field Based on Selected User

## Description
This catalog client script automatically fills the **Manager** field when a user is selected in a Service Catalog item. It uses a client-callable Script Include to fetch the manager of the selected user from the `sys_user` table.

## Files Included
- `ClientScript_AutoPopulateManager.js`
- `ScriptInclude_GetManager.js`

## Use Case
Improves user experience by reducing manual input and ensuring accurate manager data in catalog requests.

## Setup Instructions
1. Create a **Catalog Client Script** on the relevant catalog item.
2. Add the provided JavaScript to the `onChange` function of the `user` field.
3. Create a **Script Include** named `GetManager` and mark it as client-callable.
4. Ensure the catalog item has a `manager` field to populate.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var GetManager = Class.create();
GetManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManager: function() {
var userId = this.getParameter('sysparm_user_id');
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
return userGR.getValue('manager');
}
return '';
}
});
Loading