The CreatorCon Call for Content is officially open! Get started here.

I want to print the incident numbers of the newly created incidents

SOUMYADEEP CHA1
Giga Contributor

I wanted to print incident numbers: But, my first approach is printing the correct output, but the second approach is printing the wrong output. I am not able to understand why?

 

//APPROACH 1 printing the correct output
var newIncidents = [];//a new array for the incs
var counter = 1;
var incidentGR = new GlideRecord('incident');
while(counter <= 5){
  incidentGR.newRecord();
  incidentGR.short_description = 'Incident #' +counter;
  counter++;
  newIncidents.push(incidentGR.insert());
}
for(var i = 0; i < newIncidents.length; i++){
  gs.print(incidentGR.number);
}

 

//APPROACH 2 :printing the wrong output
var newIncidents = [];//a new array for the incs
var counter = 1;
var incidentGR = new GlideRecord('incident');
while(counter <= 5){
  incidentGR.newRecord();
  incidentGR.short_description = 'Incident #' +counter;
  counter++;
  newIncidents.push(incidentGR.insert());
}
for(var i = 0; i < newIncidents.length; i++){
  gs.print(newIncidents[i].number);
}

 

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron
var newIncidents = [];//a new array for the incs
var counter = 1;
var incidentGR = new GlideRecord('incident');
while(counter <= 5){
  incidentGR.newRecord();
  incidentGR.short_description = 'Incident #' +counter;
  counter++;
  newIncidents.push(incidentGR.insert()); //This will return sys_ids of records
}
for(var i = 0; i < newIncidents.length; i++){
//to get number for each you need to locate record & print

var inci=new GlideRecord('incident');
inci.get(newIncidents[i]);
  gs.print(inci.number);
}

 

Also, the first approach will not work. It will pritn same number only. Give it a check.

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

Hi,

What is that you are looking for , am a bit confused.

Generally to get newly created incidents this is what we do :

var c=0;

var check= new GlideRecord('incident');

check.addQuery('category','software');

check.setLimit(10);

check.query();

while(check.next())

{

c++

gs.print('check the :'+check.number);}

gs.print('total nnumber of record is:'+c);

 

Mark my answer correct & Helpful, if Applicable.

Thanks,
Sandeep

Hi, Sandeep thanks for your response, 

I have created 5 new incidents, but now when I want to print those incident numbers I am not able to do it. 

 

Jaspal Singh
Mega Patron
Mega Patron
var newIncidents = [];//a new array for the incs
var counter = 1;
var incidentGR = new GlideRecord('incident');
while(counter <= 5){
  incidentGR.newRecord();
  incidentGR.short_description = 'Incident #' +counter;
  counter++;
  newIncidents.push(incidentGR.insert()); //This will return sys_ids of records
}
for(var i = 0; i < newIncidents.length; i++){
//to get number for each you need to locate record & print

var inci=new GlideRecord('incident');
inci.get(newIncidents[i]);
  gs.print(inci.number);
}

 

Also, the first approach will not work. It will pritn same number only. Give it a check.

Hi Jaspal, 

Okay, now it makes sense. 

Thank you.