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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Rahul,



Don't have the exact solution handy but you can define your logic and get it done via transform scripts.


Transform Map Scripts - ServiceNow Wiki


Thanks Pradeep. Can we use glideaggregate function here. The challenge is to take only 10 servers at a time and create a incident record with specific short description and assignment group..



Right now i have a list of 800 servers.



1. I will import this data into ServiceNow using Import sets.


2. Once we have the data in ServiceNow, then i will write an ON BEFORE transform script will will aggregate 10 records from the source table.


3. Using transform maps, i will transform those 10 records into a single incident record.



Is this logic correct. Other challenge will be to link those 10 servers in the CI tab of the incident record.



Any help on this would be much appreciated.



Thanks,


Rahul kathuria


Hi Rahul,



That sounds about right. Yes, use the GlideAggregate class when counting records unless you otherwise plan to alter those records in the same operation. (See section 5.11 here.)



The table you want to use to "attach" your CIs to the incident is task_ci. It's a many-to-many table that is used to create that related list of CIs on the incident (or any task.)


Chuck Tomasi
Tera Patron

Hi Rahul,



I had to think about this for a bit, but here's what I came up with... In your transform map, run an onStart script to create a new incident and store the sys_id.


Run an onAfter script (that runs after each target record is inserted) that attaches the record to the incident (via the stored sys_id.)


In that same onAfter script, count how many records have been attached (using a GlideAggregate call for all records from the target table that have the same parent incident.) If this was the 10th record, create a new incident and start over again.



Good luck!



Transform Map Scripts - ServiceNow Wiki