insert records with different short descrition using background script

tGhadage
Tera Contributor

Hi @all

var increcord = new GlideRecord('incident');
for(i=1;i<=100;i++){
increcord.initialize();
increcord.short_description = 'test '+' '+ i;
increcord.state == 3;
increcord.insert();

here I am trying to insert 100 records into the instance using background script with different short description for each record can anyone help me how shall I do  it using script ? short description  can be different as using inc number and other sentences. 

thanks!! 

7 REPLIES 7

Sandeep Rajput
Tera Patron
Tera Patron

@tGhadage  There are multiple ways to achieve it, one way (which you are already doing in your script) is to assign a dynamic value via script increcord.short_description = 'test '+' '+ i; another way is to fetch the short description from another data source (a custom table/an attachment) and assign it to short_description field via script.

Hi @Sandeep Rajput , 

sorry actually I am not lookin unique as in test 1,2 ,3 etc. but entire different relevant short description 

OlaN
Giga Sage
Giga Sage

Hi,

A Fix Script is probably the easiest way to move forward.

It does the same thing as running a script in "Scripts - Background" but adds some nice additional features, such as saving and versioning.

 

One thing you can do, if you want to use the Incident number as part of the dynamically setting the short description, is to change the usage of .initialize() into .newRecord() 
The difference is that .newRecord() also sets the default-values for the fields that uses that feature (such as incident number).

Example:

for (var i=0; i<3; i++){
	var incGR = new GlideRecord('incident');
	incGR.newRecord();
	incGR.setValue('short_description', 'Demo inc: ' + incGR.getValue('number'));
	incGR.insert();
}

tGhadage
Tera Contributor

Sorry Actually I am not lookin unique as in test 1,2 ,3 etc. but entire different relevant short description like for eg:  '" EMAIL is slow when an attachment is involved " is there any way doing it using script