- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:48 PM
I want to show the auto populated field value on form based the selected dropdown value,dropdown contains "n" number of values.dropdown values coming from the table and populated field value should also come from that table dropdown value record.
.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2024 04:59 AM
Hi @venkata sai alu
You have to write Client Script and Script include to fetch the value from the tables.
Step 1: Implement a Client Script to Populate the Field
Next, create a Client Script to listen for changes on the dropdown (Reference field) and populate your target field based on the selected value.
1. Navigate to the System Definition > Client Scripts.
2. Click New to create a new Client Script.
3. Set the Name, and choose the Table where your form belongs.
4. In the Script field, enter your JavaScript code. Here’s a simple example assuming your Reference field is named referenced_field, and you want to populate target_field with the description (or any relevant column) from the selected record on dropdown change:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === ‘’) {
return;
}
// Makes sure a value has been selected
if (newValue) {
// Perform a GlideAjax call to get the detail from the selected record
var ga = new GlideAjax(‘YourScriptInclude’);
ga.addParam(‘sysparm_name’, ‘getRecordDetail’);
ga.addParam(‘sysparm_record_sys_id’, newValue); // Pass the sys_id of the selected record
ga.getXMLAnswer(function(response){
// Parse the response, and set the desired field’s value
var result = response; // Assuming response is the value you want to set
g_form.setValue(‘target_field’, result);
});
}
}
Step 2: Create a Script Include for Server-side Logic
Since Client Scripts run on the client side and cannot directly access server-side objects like GlideRecord for security reasons, you’ll use a GlideAjax call to interact with a Script Include.
1. Create a Script Include by navigating to System Definition > Script Includes.
2. Set the Name (use YourScriptInclude or another name as referenced in your Client Script), and ensure it’s Accessible from Client Scripts.
3. In the script field, add your server-side logic to fetch the desired record and return the relevant information. Example:
var YourScriptInclude = Class.create();
YourScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecordDetail: function() {
var recordSysId = this.getParameter(‘sysparm_record_sys_id’);
var result = ‘’;
// Assuming ‘your_table’ is the table where your records are
var gr = new GlideRecord(‘your_table’);
if(gr.get(recordSysId)) {
// Example: Extracting the ‘description’ field
result = gr.getValue(‘description’);
}
return result;
},
type: ‘YourScriptInclude’
});
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 10:22 PM
you can use the onChange client script for this.
Thanks
dgarad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 10:41 PM
Hi @venkata sai alu follow the steps as mentioned in below thread
Please mark reply as Helpful/Correct, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2024 04:59 AM
Hi @venkata sai alu
You have to write Client Script and Script include to fetch the value from the tables.
Step 1: Implement a Client Script to Populate the Field
Next, create a Client Script to listen for changes on the dropdown (Reference field) and populate your target field based on the selected value.
1. Navigate to the System Definition > Client Scripts.
2. Click New to create a new Client Script.
3. Set the Name, and choose the Table where your form belongs.
4. In the Script field, enter your JavaScript code. Here’s a simple example assuming your Reference field is named referenced_field, and you want to populate target_field with the description (or any relevant column) from the selected record on dropdown change:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === ‘’) {
return;
}
// Makes sure a value has been selected
if (newValue) {
// Perform a GlideAjax call to get the detail from the selected record
var ga = new GlideAjax(‘YourScriptInclude’);
ga.addParam(‘sysparm_name’, ‘getRecordDetail’);
ga.addParam(‘sysparm_record_sys_id’, newValue); // Pass the sys_id of the selected record
ga.getXMLAnswer(function(response){
// Parse the response, and set the desired field’s value
var result = response; // Assuming response is the value you want to set
g_form.setValue(‘target_field’, result);
});
}
}
Step 2: Create a Script Include for Server-side Logic
Since Client Scripts run on the client side and cannot directly access server-side objects like GlideRecord for security reasons, you’ll use a GlideAjax call to interact with a Script Include.
1. Create a Script Include by navigating to System Definition > Script Includes.
2. Set the Name (use YourScriptInclude or another name as referenced in your Client Script), and ensure it’s Accessible from Client Scripts.
3. In the script field, add your server-side logic to fetch the desired record and return the relevant information. Example:
var YourScriptInclude = Class.create();
YourScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecordDetail: function() {
var recordSysId = this.getParameter(‘sysparm_record_sys_id’);
var result = ‘’;
// Assuming ‘your_table’ is the table where your records are
var gr = new GlideRecord(‘your_table’);
if(gr.get(recordSysId)) {
// Example: Extracting the ‘description’ field
result = gr.getValue(‘description’);
}
return result;
},
type: ‘YourScriptInclude’
});
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 02:47 AM
Thank you.