OGeza
Tera Expert

Sometimes you need to multiply records on a table, such as an Agile Story, Incident, SCTASK, etc.

This Fix Script will filter the table that you define based on breadcrumbs, and make duplicates from every record that returned.

You can re-assign the records as well if you add UserID's in the assignedToUsers array.

If you don't want to re-assign them, comment out the line: gr.assigned_to = assignedToUsers[i]; and add as many random numbers to the array as many duplicates you want to create.

//Enter the table name
var table = 'rm_story';

//Enter filer breadcrumbs between quotation marks here:
var breadcrumbs = "short_descriptionSTARTSWITH[TRA^assigned_toISEMPTY";

//Enter the SysIDs of the users that you want to assign the new records to. Add them between quotation marks, divided by commas
//The script will create as many duplicates as many SysIds you add to the "assignedToUsers" array
//Make sure that the user is a member of the Assignment group, or the record will be created without an assignee!
var assignedToUsers = ["c4ba1272db08c59cc15754ebd39619co", "e89a8432dlw8c59cc15754ebd39619co"];

var gr = new GlideRecord(table);
gr.addEncodedQuery(breadcrumbs);
gr.query();
while (gr.next()) {
	//clone the old sysID for copying the attachments later
    var oldSysId = gr.sys_id.toString();
	
    for (var i = 0; i < assignedToUsers.length; i++) {
		//assign a the next available number on the table to the record
        gr.number = new NumberManager(table).getNextObjNumberPadded();
		//modify the Assign to value to the one in the array
        gr.assigned_to = assignedToUsers[i];
		//create the duplicate, and save the new record's sys_id
        var newSysId = gr.insert();
		//copy the attachments from the original record to the duplicated one
        new GlideSysAttachment().copy(table, oldSysId, table, newSysId);
        gr.update();

        gs.log(gr.getDisplayValue('short_description') + " GOT COPIED " + parseInt(i + 1) + " TIMES.", " Multiply records from filer breadcrums");

    }

}
Version history
Last update:
‎03-18-2022 01:23 AM
Updated by: