Auto-Populate the Assigned to field if similar Serial number is found in system

Preksha Kapoor
Tera Contributor

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

 

PrekshaKapoor_1-1742396308796.png

 

8 REPLIES 8

priyatam_pvp
Tera Guru

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

Rohit  Singh
Mega Sage

Hi @Preksha Kapoor ,

 

In assigned_to what value you want to show? Also the serial number should check in which table?

 

 

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.

Hi @Preksha Kapoor ,

 

Please follow the below step:

  1. Create OnChange Catalog Client Script. Field ->Serial Number
  2. Create Client Callable Script Include. 
  3. Do a glide record in alm_asset . addQuery("serial_number",this.getParameter("sysparm_asset_id"));
  4. If record found then return gr.assigned_to
  5. In Client Script if answer is not null the g_form.setValue("variable_name(assigned_to),answer)
  6. 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