Using Background script I need to create 10 incident records in incident table?

Lucky18
Kilo Contributor

And also out of 10 records 5 records caller id should be one user and the other 5 records should be another user.

As I am new to service now please let me know to code it

Thanks in advnace!

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi Shankar,

I have used the following script and the records are created.

 

for(var i = 0 ; i < 5 ; i++)
{
var gr = new GlideRecord('incident');
gr.initialize();
gr.caller_id = '62826bf03710200044e0bfc8bcbe5df1';
gr.insert();
}
for(var i = 0 ; i < 5 ; i++)
{
var gr = new GlideRecord('incident');
gr.initialize();
gr.caller_id = 'a8f98bb0eb32010045e1a5115206fe3a';
gr.insert();
}

 

If the above code doesn't work for you, check for ACLs that might prevent you writing on the field. I ran the above code and records got created. See the attachment.

find_real_file.png

View solution in original post

13 REPLIES 13

Hi,

 

Use this 

grIncident.setValue('caller_id', callerSysId[i]);

Lucky18
Kilo Contributor

yeah buddy even I have done the same thing ,still the caller id is empty

 

Ah forgot the [i]. Try this:

var callerSysId = '0a826bf03710200044e0bfc8bcbe5d7a,be82abf03710200044e0bfc8bcbe5d1c';
callerSysId = callerSysId.split(',');

for(var i = 0; i < callerSysId.length; i++) {
	var loopInt = 5;

	for(var j = 0; j < loopInt; j++) {
		var grIncident = new GlideRecord('incident');
		grIncident.newRecord();
		grIncident.setValue('caller_id', callerSysId[i]);
		grIncident.insert();
	}
}

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Lucky18
Kilo Contributor

No buddy still its showing empty,i dunno why?

The last code I pasted is validated:

find_real_file.png

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn