Automatically create a schedule incident and assign it to a group and user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2022 11:06 AM
I'm trying to create an incident through scheduled job. I have written a glide script . The incident created should be to assigned to a particular group and user.
Here is the script. I tried assign roles also, which did not assign the user. please help me assign user in the glidereport.
var Incid1 = new GlideRecord("cmdb_ci");
Incid1.initialize();
var user = new GlideRecord("'sys_user'");
var Username=John Doe";
Incid1.caller_id = gs.getUserID();
Incid1.short_description = "Checks for Risky sign-in's and risky Users";
Incid1.description = "Checks for Risky sign-in's and risky Users";
Incid1.priority = 2;
Incid1.category = "Security";
if (user.get(Username))
{
gs.log('Name: ' + user.name);
Incid1.Assignedto=user.name;
}
Incid1.insert();
- Labels:
-
Script Debugger

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2022 11:12 AM
var Incid1 = new GlideRecord("incident");
Incid1.initialize();
Incid1.caller_id = gs.getUserID();
Incid1.short_description = "Checks for Risky sign-in's and risky Users";
Incid1.description = "Checks for Risky sign-in's and risky Users";
Incid1.priority = 2;
Incid1.category = "Security";
Incid1.assigned_to='<<sys id of John Doe>>';
Incid1.insert();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 06:24 AM
Hello
Did the script work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2022 11:13 AM
It looks like you're creating a glide record on the configuration item table not the incident.
var gr = new GlideRecord('Incident');
Also you are missing a quotation on your string declaration var Username= "John Doe";

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2022 11:14 AM
Hi,
Whenever you consider creating a scheduled job that executes some script, think again, and consider using Flow designer for the same. It can cover most use cases, and will in most cases not require you to write a single line of code.
Check out the learning materials on the Developer site to get started, or ask, if you need additional help.