diff --git a/Specialized Areas/Auto-Populate Manager Field Based on Selected User/ClientScript_AutoPopulateManager.js b/Specialized Areas/Auto-Populate Manager Field Based on Selected User/ClientScript_AutoPopulateManager.js new file mode 100644 index 0000000000..cae1f5d4be --- /dev/null +++ b/Specialized Areas/Auto-Populate Manager Field Based on Selected User/ClientScript_AutoPopulateManager.js @@ -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); + }); +} diff --git a/Specialized Areas/Auto-Populate Manager Field Based on Selected User/README.md b/Specialized Areas/Auto-Populate Manager Field Based on Selected User/README.md new file mode 100644 index 0000000000..1b1cfc246d --- /dev/null +++ b/Specialized Areas/Auto-Populate Manager Field Based on Selected User/README.md @@ -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. + diff --git a/Specialized Areas/Auto-Populate Manager Field Based on Selected User/ScriptInclude_GetManager.js b/Specialized Areas/Auto-Populate Manager Field Based on Selected User/ScriptInclude_GetManager.js new file mode 100644 index 0000000000..56062c19df --- /dev/null +++ b/Specialized Areas/Auto-Populate Manager Field Based on Selected User/ScriptInclude_GetManager.js @@ -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 ''; + } +});