Create Bulk records of one table from a Record Producer

DEV976
Tera Expert

Hi Community, 
There is a Record Producer name "Change Management". it is created on a change request table. It creates one record at a time after submitting the record producer. I want to make multiple records at one time. there is a variable name "select no. of record", with the name "rec", where how many numbers will be written, then the same number of records will be created and the short description will be populated according to record producer and number will be incremented

DEV976_0-1689095130004.png

 

1 ACCEPTED SOLUTION

Punit S
Giga Guru

To modify the "Change Management" Record Producer to create multiple records at once, you can follow these steps:

  1. Open the "Change Management" Record Producer: Access the ServiceNow platform and navigate to the form or catalog item for the "Change Management" Record Producer.

  2. Modify the variable and script: Locate the variable named "select no. of record" (with the name "rec") in the form or catalog item configuration. Update the variable to allow the selection of multiple records to be created.

  3. Adjust the script: Add a script to the Record Producer that handles the creation of multiple records based on the selected number.

 

// Get the selected number of records
var numberOfRecords = parseInt(current.variables.rec);

// Get the short description from the Record Producer
var shortDescription = current.short_description;

// Loop to create the desired number of records
for (var i = 0; i < numberOfRecords; i++) {
  // Create a new record
  var newRecord = new GlideRecord('change_request');
  newRecord.initialize();
  
  // Set the short description
  newRecord.short_description = shortDescription + ' ' + (i + 1); // Increment the number
  
  // Add any other desired field values
  
  // Insert the new record
  newRecord.insert();
}

 

  1. Save and test the changes: Save the modifications to the Record Producer and test it by submitting a request with the updated "select no. of record" variable. Multiple records should be created based on the selected number, with the short description populated according to the Record Producer and incremented number.

Remember to adjust the script according to your specific table name, field names, and any additional fields you want to populate in the created records.

Please note that modifying the Record Producer requires appropriate access and knowledge of ServiceNow configuration. It's recommended to test the changes thoroughly in a non-production environment before deploying them to a live environment.

 

Please mark my answer as a solution/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal.

Thanks,
Punit

View solution in original post

2 REPLIES 2

Sid_Takali
Kilo Patron
Kilo Patron

Hi @DEV976 refer this https://www.youtube.com/watch?v=Aeq70eHMUR4

 

Regards,

Siddharam

In this video I show you have you with the leverage of flow, can create multiple records in multiple tables through one record producer. Video recorded in Orlando Release

Punit S
Giga Guru

To modify the "Change Management" Record Producer to create multiple records at once, you can follow these steps:

  1. Open the "Change Management" Record Producer: Access the ServiceNow platform and navigate to the form or catalog item for the "Change Management" Record Producer.

  2. Modify the variable and script: Locate the variable named "select no. of record" (with the name "rec") in the form or catalog item configuration. Update the variable to allow the selection of multiple records to be created.

  3. Adjust the script: Add a script to the Record Producer that handles the creation of multiple records based on the selected number.

 

// Get the selected number of records
var numberOfRecords = parseInt(current.variables.rec);

// Get the short description from the Record Producer
var shortDescription = current.short_description;

// Loop to create the desired number of records
for (var i = 0; i < numberOfRecords; i++) {
  // Create a new record
  var newRecord = new GlideRecord('change_request');
  newRecord.initialize();
  
  // Set the short description
  newRecord.short_description = shortDescription + ' ' + (i + 1); // Increment the number
  
  // Add any other desired field values
  
  // Insert the new record
  newRecord.insert();
}

 

  1. Save and test the changes: Save the modifications to the Record Producer and test it by submitting a request with the updated "select no. of record" variable. Multiple records should be created based on the selected number, with the short description populated according to the Record Producer and incremented number.

Remember to adjust the script according to your specific table name, field names, and any additional fields you want to populate in the created records.

Please note that modifying the Record Producer requires appropriate access and knowledge of ServiceNow configuration. It's recommended to test the changes thoroughly in a non-production environment before deploying them to a live environment.

 

Please mark my answer as a solution/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal.

Thanks,
Punit