From ba8b6bac1335aa3524b59e7a1e140ce2ac010b6c Mon Sep 17 00:00:00 2001 From: kmxo Date: Tue, 7 Oct 2025 06:46:11 -0300 Subject: [PATCH] Client side --- .../Call SI to recover User data/README.md | 5 +++ .../Call SI to recover User data/script.js | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Call SI to recover User data/README.md create mode 100644 Client-Side Components/Client Scripts/Call SI to recover User data/script.js diff --git a/Client-Side Components/Client Scripts/Call SI to recover User data/README.md b/Client-Side Components/Client Scripts/Call SI to recover User data/README.md new file mode 100644 index 0000000000..d159135c0d --- /dev/null +++ b/Client-Side Components/Client Scripts/Call SI to recover User data/README.md @@ -0,0 +1,5 @@ +# Call Script Include to recover User data + +In this onChange Client Script, the scenario is this: +- In a form, we have a reference field to the User table to allow our user to select any user within the platform. +- Once a user is selected, we are passing that Sys ID to recover more information regarding the selected record. diff --git a/Client-Side Components/Client Scripts/Call SI to recover User data/script.js b/Client-Side Components/Client Scripts/Call SI to recover User data/script.js new file mode 100644 index 0000000000..be7141d1e1 --- /dev/null +++ b/Client-Side Components/Client Scripts/Call SI to recover User data/script.js @@ -0,0 +1,33 @@ +/* +Type: onChange +Field: a reference to the User table +*/ +function onChange(control, oldValue, newValue, isLoading, isTemplate) { + if (isLoading || newValue === '') { + return; + } + + var test = newValue; + + //The Script Include called here can be found in: + //Server-Side Components / Script Includes / Get User Data by Id + //It is in Global scope + var ga = new GlideAjax('GetUserData');//script include name + ga.addParam('sysparm_name', 'GetUserBy_id'); //method to be called + ga.addParam('sysparm_userid', test); //send a parameter to the method. + ga.getXMLAnswer(userInfoParse); + + function userInfoParse(response) { + if (response == '') { + g_form.addErrorMessage('User not found with the informed sys_id.'); + } else { + //alert(response); + var obj = JSON.parse(response); + g_form.setValue('u_first_name', obj.first_name.toString()); + g_form.setValue('u_last_name', obj.last_name.toString()); + g_form.setValue('u_email', obj.email.toString()); + } + + } + +}