Need help to auto populate display name in Parent field with the help of SerialNumber for consumable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2024 02:28 AM
Hi All, Need some, I have created a bulk uploader for uploading Conusmable data in Bulk. In the sheet i have Serial Number as one of the column in which i am providing the serial number of the asset against which consumable is allocated. But while uploading the data in alm_consumable table Serial Number is not getting populated. When checked as per the OOB process when we allocate consumable to any user the details what we need to fill is Asset (in which display name is getting populated). Now i am not able to match the serial number with display name to get it auto populated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2024 03:01 AM
Hi @Kalpeshjathar30,
Configure the Client Script:
- Name: Give your client script a meaningful name, like "Auto Populate Parent Field Based on Serial Number".
- Table: Select the table where you want this script to run (e.g., alm_consumable).
- Type: Select onChange.
- Field Name: Select the field that triggers this script (e.g., serial_number).
- UI Type: Select All or Mobile/Service Portal based on your requirements.
Script:
(function executeRule(current, previous /*null when async*/) {
// Get the value of the serial number field
var serialNumber = g_form.getValue('serial_number');
if (serialNumber) {
// Create a GlideAjax object to call a script include
var ga = new GlideAjax('GetParentBySerialNumber');
ga.addParam('sysparm_name', 'getParentDisplayName');
ga.addParam('sysparm_serial_number', serialNumber);
ga.getXMLAnswer(function(response) {
var parentDisplayName = response.responseXML.documentElement.getAttribute('answer');
if (parentDisplayName) {
// Set the value of the parent field with the display name
g_form.setValue('parent', parentDisplayName);
}
});
}
})(current, previous);
Configure the Script Include:
- Name: Give your script include a meaningful name, like "GetParentBySerialNumber".
- API Name: This will be auto-filled based on the name you provide.
- Client Callable: Check this box to make it callable from client scripts.
Script:
var GetParentBySerialNumber = Class.create();
GetParentBySerialNumber.prototype = {
initialize: function() {
},
getParentDisplayName: function(serialNumber) {
var parentDisplayName = '';
var gr = new GlideRecord('alm_consumable');
gr.addQuery('serial_number', serialNumber);
gr.query();
if (gr.next()) {
parentDisplayName = gr.getDisplayValue('parent');
}
return parentDisplayName;
},
type: 'GetParentBySerialNumber'
};
Thank you, please make helpful if you accept the solution.