gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
In servicenow i need to print the incidents in background script whose caller is…
- User
In servicenow i need to print the incidents in background script whose caller is inactive and state is not resolved, cancelled and closed
- Assistant
To print incidents in ServiceNow whose caller is inactive and whose state is not resolved, canceled, or closed, you can use the following background script. This script queries the incident table (
incident) for the specified conditions.// Define a GlideRecord instance for the incident table var gr = new GlideRecord('incident'); // Query for incidents where the caller is inactive gr.addJoinQuery('sys_user', 'caller_id', 'sys_id') .addCondition('active', '=', 'false'); // Add conditions for the state of the incident // Note: Assuming the state field uses integer values where states are: // New = 1, In Progress = 2, On Hold = 3, Resolved = 6, Closed = 7, Canceled = 8, etc. gr.addQuery('state', '!=', 6); // Not Resolved gr.addQuery('state', '!=', 7); // Not Closed gr.addQuery('state', '!=', 8); // Not Canceled // Query to filter results gr.query(); // Loop through the results and print required details while (gr.next()) { gs.print('Incident Number: ' + gr.getValue('number') + ', Short Description: ' + gr.getValue('short_description') + ', Caller: ' + gr.getDisplayValue('caller_id') + ', State: ' + gr.getDisplayValue('state')); }