From b43f99293b1ef292e02ec9d677913415b043fb71 Mon Sep 17 00:00:00 2001 From: DavidMarcial <60865187+DavidMarcial@users.noreply.github.com> Date: Thu, 30 Oct 2025 08:40:06 +0100 Subject: [PATCH 1/4] Create onChangeClientScript.js --- .../onChangeClientScript.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Autopopulate user information fields/onChangeClientScript.js diff --git a/Client-Side Components/Catalog Client Script/Autopopulate user information fields/onChangeClientScript.js b/Client-Side Components/Catalog Client Script/Autopopulate user information fields/onChangeClientScript.js new file mode 100644 index 0000000000..b7f32dc84b --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Autopopulate user information fields/onChangeClientScript.js @@ -0,0 +1,23 @@ +/* +* In order for this to work make sure to have an onChange catalog client script on a variable that is type Requested For. This variable +* already autopopulates the logged in user with its OOB functionality. In the updateUserFields function you can add any other user fields +* that you might need. +*/ + +function onChange(control, oldValue, newValue, isLoading) { + //This variable will store the sys_id of the user that populates in your requested for variable + var userID = newValue; + + var ga = new GlideAjax(ReferenceQualifierAjaxHelper); + ga.addParam('sysparm_name', 'getUserInformation'); + ga.addParam('sysparm_user', userID); + ga.getXMLAnswer(updateUserFields); + + function updateUserFields(response) { + var returnedData = JSON.parse(response); + g_form.setValue("email", returnedData.email); + g_form.setValue("location", returnedData.location); + g_form.setValue("title", returnedData.title); + g_form.setValue("phone", returnedData.phone); + } +} From 6a5f90a993fa2844ccc0e3796add780387572634 Mon Sep 17 00:00:00 2001 From: DavidMarcial <60865187+DavidMarcial@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:03:04 +0100 Subject: [PATCH 2/4] Create ClientCallableScriptInclude.js --- .../ClientCallableScriptInclude.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Autopopulate user information fields/ClientCallableScriptInclude.js diff --git a/Client-Side Components/Catalog Client Script/Autopopulate user information fields/ClientCallableScriptInclude.js b/Client-Side Components/Catalog Client Script/Autopopulate user information fields/ClientCallableScriptInclude.js new file mode 100644 index 0000000000..0e17bbe045 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Autopopulate user information fields/ClientCallableScriptInclude.js @@ -0,0 +1,25 @@ +/* +* The following is a client callable script include. This can be used with the onChange Client script to be able to gather the data on the server side +*/ + +var ReferenceQualifierAjaxHelper = Class.create(); +ReferenceQualifierAjaxHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, { + getUserInformation : function() { + var userID = this.getParameter('sysparm_user'); + var userRec = new GlideRecord('sys_user'); + + if(userRec.get(userID)) { + var results = { + "email" : userRec.getValue('email'), + "department" : userRec.getValue('department'), + "title" : userRec.getValue('title'), + "phone" : userRec.getValue('phone') + }; + + return JSON.stringify(results) + } + + }, + + type: 'ReferenceQualifierAjaxHelper' +}); From 53592db3acd9d2ade68581f9466485e9106430a0 Mon Sep 17 00:00:00 2001 From: DavidMarcial <60865187+DavidMarcial@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:04:16 +0100 Subject: [PATCH 3/4] Updated onChangeClientScript.js removed location and added department field instead --- .../onChangeClientScript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client-Side Components/Catalog Client Script/Autopopulate user information fields/onChangeClientScript.js b/Client-Side Components/Catalog Client Script/Autopopulate user information fields/onChangeClientScript.js index b7f32dc84b..805547fe44 100644 --- a/Client-Side Components/Catalog Client Script/Autopopulate user information fields/onChangeClientScript.js +++ b/Client-Side Components/Catalog Client Script/Autopopulate user information fields/onChangeClientScript.js @@ -16,7 +16,7 @@ function onChange(control, oldValue, newValue, isLoading) { function updateUserFields(response) { var returnedData = JSON.parse(response); g_form.setValue("email", returnedData.email); - g_form.setValue("location", returnedData.location); + g_form.setValue("department", returnedData.department); g_form.setValue("title", returnedData.title); g_form.setValue("phone", returnedData.phone); } From 06b12bf987abb39fcecac9652210db0c0ba57289 Mon Sep 17 00:00:00 2001 From: DavidMarcial <60865187+DavidMarcial@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:10:31 +0100 Subject: [PATCH 4/4] Create README.md --- .../Autopopulate user information fields/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Autopopulate user information fields/README.md diff --git a/Client-Side Components/Catalog Client Script/Autopopulate user information fields/README.md b/Client-Side Components/Catalog Client Script/Autopopulate user information fields/README.md new file mode 100644 index 0000000000..0614b60044 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Autopopulate user information fields/README.md @@ -0,0 +1,6 @@ +## Overview +This onchange catalog client script and script inlcude work together autopopulate the user fields that might show up on a catalog item. In the +global scope you will have to create the client callable script include to be able to use the Ajax call that is in the on change client script. +In this example we use the OOB Requested For field that already auto populates the user that is logged in then we go to the server to get that +users information. The fields that are brough back are the ones that are in the code but you can modify to bring back more or less fields if needed. +