- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 11:34 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 01:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 01:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 06:10 AM - edited 07-13-2023 06:20 AM
Hi @Ratnakar7, thanks for the above code.