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

Insert/Create multiple no. of records from record producer

DevYadav
Tera Contributor

Hi Community,

 

I have a requirement 

 

As we know that record producer can generate one new record after clicking on submit button. Record producer is create on incident table.I have add one variable in here that is 'how many records should be create' with name 'inc_create. There is another field name assign to that has map to assigned to in incident table. If we write 3 on 'how many records should be create' then three new incident records should be create and assigned to should be autopopulate to these newly created records.

I am using this code on record producer's script:

var num_rec = parseInt(current.variables.inc_create);
var f1 = current.assign;
for (var i = 0; i < num_rec; i++) {

var rec = new GlideRecord('incident');
rec.initialize();

rec.assign_to = f1 + ' ' + (i + 1);

rec.insert();
}

Thanks in Advance

 

1 ACCEPTED SOLUTION

Ratnakar7
Mega Sage

Hi @DevYadav ,

 

The assign_to field in the Incident table is a reference field, so you need to set it with a reference value. In your code, you are concatenating the assignment value as a string.

Here's modified code:

 

var num_rec = parseInt(current.variables.inc_create);
var f1 = current.variables.assign_to; // Assuming the variable name is "assign_to"
for (var i = 0; i < num_rec; i++) {
    var rec = new GlideRecord('incident');
    rec.initialize();
    rec.setValue('assign_to', f1);
    rec.insert();
}

 

 

Thanks,

Ratnakar

 

View solution in original post

2 REPLIES 2

Ratnakar7
Mega Sage

Hi @DevYadav ,

 

The assign_to field in the Incident table is a reference field, so you need to set it with a reference value. In your code, you are concatenating the assignment value as a string.

Here's modified code:

 

var num_rec = parseInt(current.variables.inc_create);
var f1 = current.variables.assign_to; // Assuming the variable name is "assign_to"
for (var i = 0; i < num_rec; i++) {
    var rec = new GlideRecord('incident');
    rec.initialize();
    rec.setValue('assign_to', f1);
    rec.insert();
}

 

 

Thanks,

Ratnakar

 

Hi @Ratnakar7, thanks for the above code.