Auto-Populate the Assigned to field if similar Serial number is found in system
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:00 AM
Hi All,
we want to auto populate a singleline text box field with the assigned user name if the serial number entered in the form already exist
Attached is the screenshot of the same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:06 AM
On change Serial Number client script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CheckSerialNumber');
ga.addParam('sysparm_name', 'getAssignedUser');
ga.addParam('sysparm_serialNumber', newValue);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('assigned_to', response); // Populating the Assigned To field
}
});
}
script Include :
var CheckSerialNumber = Class.create();
CheckSerialNumber.prototype = {
initialize: function() {},
getAssignedUser: function(serialNumber) {
var gr = new GlideRecord('cmdb_ci'); // Change to correct table if needed
gr.addQuery('serial_number', serialNumber);
gr.query();
if (gr.next()) {
return gr.getValue('assigned_to'); // Fetch assigned user name
}
return ''; // Return empty if no match found
},
type: 'CheckSerialNumber'
};
and Assigned to is a reference field so sending sys_id to map the user.
Please mark it as helpful
Regards
Priyatam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:12 AM
Hi @Preksha Kapoor ,
In assigned_to what value you want to show? Also the serial number should check in which table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:14 AM
Serial number should check in alm_asset table
In Assigned to it should populate the users name if the serial number entered already exist in system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:31 AM
Hi @Preksha Kapoor ,
Please follow the below step:
- Create OnChange Catalog Client Script. Field ->Serial Number
- Create Client Callable Script Include.
- Do a glide record in alm_asset . addQuery("serial_number",this.getParameter("sysparm_asset_id"));
- If record found then return gr.assigned_to
- In Client Script if answer is not null the g_form.setValue("variable_name(assigned_to),answer)
- Else g_form.addInfoMessage("Serial Number Does not exist");
This is a high level approach which you can follow.
If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.
Regards,
Rohit