Unable to Create Incident Using Scheduled Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 07:55 PM
Hi,
How can I create an incident weekly once using a scheduled job? I have tried, but I'm unable to create the incident from the scheduled job. please help me?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 10:11 PM
script looks good to me.
can you add try catch block to know if any exception is thrown? you didn't share the error from system logs
try to use this for line 5
incidentGR.setDisplayValue('assignment_group','Hardware');
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2025 03:46 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 10:17 PM
Your script is mostly correct, but I see potential issues that might prevent the incident from being created successfully.
Little bit I Edit a script .
var incidentGR = new GlideRecord('incident');
incidentGR.initialize();
incidentGR.short_description = 'Certificate Alert: test';
incidentGR.priority = 5;
incidentGR.assignment_group.setDisplayValue('Hardware');
incidentGR.caller_id.setDisplayValue('System Administrator');
incidentGR.state = 1;
incidentGR.insert();
gs.log('Ticket Created: ' + incidentGR.short_description);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 08:56 PM
Hi @Hari S1
I Hope you are doing well!
Here is the step you can follow this .
Navigate to: System Definition → Scheduled Jobs → New Configure the Scheduled Job:
Name: Create Weekly Incident.
Run As: <Your User or System User>
Active: ✅ (Checked)
Repeat Interval: Weekly.
Time: Choose the desired time.
Step 2: Add a Script to Create an Incident
In the Script field of the scheduled job, add the following script:
(function executeScheduleJob() {
var inc = new GlideRecord('incident'); // Access the Incident table
inc.initialize(); // Create a new record
// Set the required fields
inc.short_description = "Weekly Incident - Auto Created";
inc.description = "This incident is created automatically by a scheduled job.";
inc.impact = 2; // Set impact (1-High, 2-Medium, 3-Low)
inc.urgency = 2; // Set urgency (1-High, 2-Medium, 3-Low)
inc.priority = 3; // Set priority based on impact & urgency
inc.caller_id = "System Administrator"; // Set caller (Modify as needed)
inc.insert(); // Insert the new incident record
})();
Step 3: Save and Test
Save the Scheduled Job
Run it manually for testing:
Click on Execute Now to check if an incident is created.
Verify:
Go to Incident → All and check if the new incident appears.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 09:52 PM
Hi @SyedMahemoH .
I have made changes to the script using your suggestions, but the incident is still not being created in the Incident table. I can see an error in the logs.
Scheduled Job
system logs - error