- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 04:40 AM
Hi,
I want to auto populate the user details based on the user selection in the Opened for:
Please help me out i want to use the Scriptinclude for the same.
Kindly help me out onChange and Scriptinclude for the same.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 04:50 AM
Hi @kranthi2
Please refer below link
Regards,
Dharmaraj
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 05:18 AM
Hi @kranthi2
To auto-populate user details based on the user selection in the 'Opened for' field, you can use a client script in ServiceNow.
Here are the steps:
1. Navigate to System Definition > Client Scripts in ServiceNow.
2. Click on New to create a new client script.
3. Fill in the necessary fields:
- Name: Give a name to your client script.
- Table: Select the table where you want this script to run.
- Type: Select onChange.
- Field name: Select the 'Opened for' field.
4. In the Script field, write a script to fetch the user details.
Here is a sample script:
javascript
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Call a GlideAjax
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name', 'getUserDetails');
ga.addParam('sysparm_user_id', newValue);
ga.getXML(Answer);
}
function Answer(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var userObj = JSON.parse(answer);
//Set the user details to the respective fields g_form.setValue('field_name', userObj.field_value);
}
5. In the above script, 'GetUserDetails' is a Script Include which has a function 'getUserDetails' that fetches the user details based on the user id.
6. Click on Submit to save the client script.
Remember to replace 'field_name' and 'field_value' with the actual field names and values you want to set.
This script will run every time a user is selected in the 'Opened for' field and auto-populate the user details in the respective fields.
Regards
Shaqeel
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 10:00 PM
Hi @kranthi2 ,
Sorry for the late response
You can select the user or system admin role that calls the script.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 05:05 AM
You can auto-populate user details in Virtual Agent by using a Lookup Utility to select a user and then a Script block to fetch fields like location, department, and manager from the sys_user table using GlideRecord. Store them in "vaVars" to use later in the flow.