Automatically create a schedule incident and assign it to a group and user

Shree Nag
Tera Expert

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();

4 REPLIES 4

AnirudhKumar
Mega Sage
Mega Sage
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();

Hello @Shree Nag ,

Did the script work?

elcaro
Tera Contributor

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";

OlaN
Giga Sage
Giga Sage

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.