Script to create incident

Rahul Kathuria
Tera Expert

Hi Everyone,

We have a spreadsheet that had a list of servers in Column A, could you auto create a priority E ticket for every 10 servers in that spreadsheet???   For example, we have 800 servers that need to be queried for patch levels. We want to create 80 tickets where each ticket includes 10 servers.   All tickets would have the same attributes…priority E, same assignment group, etc.

further, we would like to ink those 10 servers in the CI tab of the incident record.

Thanks,

Rahul kathuria

16 REPLIES 16

Chuck, do you have a sample of this onstart transform script.?


Hi Chuck/Pradeep,



Can you please help here..i am trying to write an on start script to create incident and then on after script to calculate record count but it doesnot seem to work..



Thanks,


Rahul


Hi Rahul,



The onStart script is pretty simple. (none of this is tested, but you should get the idea.)



var inc = new GlideRecord('incident');


inc.newRecord();


// Set other fields like state, short_description, etc. here


var incId = inc.insert();



Now incId is global and known to your other transform scripts.


onAfter looks something like this:


// Count how many CIs are attached to incId


// If there are 10, create a new one


var tc = new GlideAggregate('task_ci');


tc.addAggregate('COUNT');


tc.addQuery('task', incId);


tc.query();


if (tc.next()) {


  var count = tc.getAggregate('COUNT');


  if (count >= 10) {


  // Create new incident


  var inc = new GlideRecord('incident');


  inc.newRecord();


  // Other fields


  incId = inc.insert();


  }


}



// Attach this CI to the task


var newTc = new GlideRecord('task_ci');


newTc.newRecord();


newTc.task = incId;


newTc.ci_item = target.sys_id;


newTc.insert();


Rahul Kathuria
Tera Expert

Hi Chuck,


This is not working. I imported 723 records and   It created 723 distinct incidents.


find_real_file.png



find_real_file.png



Thanks,


Rahul kathuria


Actually, when i am trying to import 723 records and running that transform, it is created 723+723/10 =723+73= 796 incidents.


Is there a way to suppress 723 unwanted incidents?



find_real_file.png