Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2024 03:40 AM
Hi esperts , need some advice . i have a business rule in native UI but how can i get all the user asset to pulled in when open an incident ?
// Check if the u_imapcted_asset field is already populated
if (!current.u_imapcted_asset.nil()) {
gs.addInfoMessage('Assets already loaded.');
} else {
// Get the caller's Sys ID from the incident ticket
var callerId = current.caller_id;
// Query the cmdb_model_category table to find categories containing "computer" in their name
var categoryGr = new GlideRecord('cmdb_model_category');
categoryGr.addQuery('name', 'CONTAINS', 'computer');
categoryGr.query();
var categoryIds = [];
while (categoryGr.next()) {
categoryIds.push(categoryGr.getUniqueValue());
}
if (categoryIds.length === 0) {
gs.addErrorMessage('No computer-related categories found');
} else {
// Query the alm_asset table to find the assets assigned to the caller and matching the computer-related categories
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('assigned_to', callerId);
assetGr.addQuery('model_category', 'IN', categoryIds);
assetGr.query();
var assetList = [];
while (assetGr.next()) {
var displayName = assetGr.getValue('display_name') || 'No display name';
var serialNumber = assetGr.getValue('serial_number') || 'No serial number';
var assetSysId = assetGr.getUniqueValue(); // Get the Sys ID of the asset
var assetInfo = displayName + ' (Serial: ' + serialNumber + ')';
assetList.push(assetSysId); // Add the Sys ID to the list
gs.addInfoMessage('Asset found: ' + assetInfo); // For debugging purposes
}
if (assetList.length > 0) {
var assetListStr = assetList.join(',');
current.u_imapcted_asset = assetListStr; // Set the list box field to the comma-separated Sys IDs
} else {
gs.addErrorMessage('Asset for Caller not found');
}
}
}
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 07:10 AM
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 07:10 AM
managed to make it work