gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Hi , in servicenow i want to print last 10 incidents raised by the user who was inactive…
- User
Hi , in servicenow i want to print last 10 incidents raised by the user who was inactive right now. Through background script
- Assistant
To achieve this task in ServiceNow using a background script, you would need to write a GlideRecord query that fetches incidents created by users who are currently inactive. This involves two main steps: finding users who are inactive and then finding incidents created by those users. Here is a sample script that demonstrates this:
// GlideRecord on the User table to find inactive users var inactiveUsers = []; var userGr = new GlideRecord('sys_user'); userGr.addQuery('active', false); // Filter for inactive users userGr.query(); while (userGr.next()) { inactiveUsers.push(userGr.sys_id.toString()); } // GlideRecord on the Incident table to find the last 10 incidents created by inactive users var incidentGr = new GlideRecord('incident'); incidentGr.addQuery('caller_id', 'IN', inactiveUsers); // Filter incidents by inactive users incidentGr.orderByDesc('sys_created_on'); // Order by creation date, descending incidentGr.setLimit(10); // Limit to last 10 records incidentGr.query(); // Print out the details of the incidents while (incidentGr.next()) { gs.print('Incident Number: ' + incidentGr.number); gs.print('Short Description: ' + incidentGr.short_description); gs.print('Created On: ' + incidentGr.sys_created_on); gs.print('Caller: ' + incidentGr.caller_id.getDisplayValue()); gs.print('----------------------------------'); }