gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
In servicenow , i have a screqitem table and there is 10 records in this and in…
- User
In servicenow , i have a sc_req_item table and there is 10 records in this and in particular record there is one field named asset and one asset is there refer to alm_hardware table. I need to take the sys id of all the assets in asset field in ritm record through background script.
- Assistant
To accomplish this task in ServiceNow, you can use a background script to retrieve the Sys ID of all assets referenced in the
sc_req_itemtable under theassetfield. Here's a simple background script to do so:// Initialize GlideRecord for the sc_req_item table var ritmGr = new GlideRecord('sc_req_item'); // Add query to filter records if needed, or use `query()` to retrieve all ritmGr.query(); while (ritmGr.next()) { // Get the sys_id value from the asset field var assetSysId = ritmGr.getValue('asset'); // Check if the field contains any data if (assetSysId) { // Print the Sys ID of the asset gs.print('RITM number: ' + ritmGr.number + ' - Asset Sys ID: ' + assetSysId); } else { gs.print('RITM number: ' + ritmGr.number + ' - No asset linked'); } }Key Points:
- The script initializes a for the table.