Hi
- User
Hi
- Assistant
Hello! How can I assist you today?
- User
I need to print last 10 incidents closed in servicenow
- Assistant
To retrieve and print the last 10 incidents closed in ServiceNow, you can create a script using the ServiceNow platform's server-side scripting capabilities, such as a Business Rule, Script Include, or in a background script (System Definition > Scripts - Background).
Below is an example of a background script to fetch the last 10 closed incidents:
javascript - User
Order by ascending
- Assistant
If you want to retrieve the last 10 closed incidents in ascending order based on the
closed_atdate (earliest closed incidents first), you can modify the script like this:javascript// Query to fetch last 10 closed incidents in ascending order (by closed_at) var grIncidents = new GlideRecord('incident'); // Access the 'incident' table grIncidents.addQuery('state', 'closed'); // Filter for incidents with state = 'closed' grIncidents.orderBy('closed_at'); // Order by the 'closed_at' field in ascending order (earliest first) grIncidents.setLimit(10); // Limit the results to 10 records grIncidents.query(); gs.print('Last 10 Closed Incidents (Ascending Order):'); while (grIncidents.next()) { gs.print('Incident Number: ' + grIncidents.getValue('number') + ', Short Description: ' + grIncidents.getValue('short_description') + ', Closed At: ' + grIncidents.getValue('closed_at')); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.