Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

business rule in native ui for updating impacted asset field . how can i do the same for SOW?

chercm
Mega Sage

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');
}
}
}
1 ACCEPTED SOLUTION

chercm
Mega Sage

managed to make it work 

 

image.png

View solution in original post

5 REPLIES 5

James Chun
Kilo Patron

Hi @chercm,

 

Sorry, what is your question?

The Business Rule should work in all UIs (native UI, Workspace, etc)

 

Cheers

@James Chun it is not working . i have the fields on the form 

@James Chun this is on native ui 

 

 

image.png

 

and this is on SOW 

 

image.png

Only one asset is showing