In servicenow, i want to print sysid field of record present in reference field named as…
- User
In servicenow, i want to print sys_id field of record present in reference field named as asset in ritm form on sc_req_item.
- Assistant
In ServiceNow, if you want to access and print the
sys_idof a record that is referenced in theassetfield of a Request Item (RITM) on thesc_req_itemtable, you can achieve this by using a script. Here’s how you can do it using a GlideRecord in a server-side script, such as a Business Rule or a Script Include.// Assuming this script is running in a Business Rule on the 'sc_req_item' table var assetSysId = current.asset.sys_id; // You can also retrieve the sys_id like this, if more explicit querying is preferred: var gr = new GlideRecord('alm_asset'); // Replace 'alm_asset' with the table that the 'asset' field points to if(gr.get(current.asset)) { var assetSysId = gr.sys_id.toString(); gs.info('Asset sys_id: ' + assetSysId); } - User
Print all in background script
- Assistant
In ServiceNow, if you want to print information to the system logs using a background script, you would typically use the
gs.log()or functions to output information to the system log. If you wish to retrieve and print all of records referenced in an field across all records, you can use a background script like this: - User
Not working
- Assistant
If the script isn't working as expected, let's troubleshoot and ensure we handle all edge cases properly. Let's make sure the script is correctly accessing and printing the of the reference field.