Script to create multiple duplicate tasks using UI Action ***Please Assist***

Still Learning
Kilo Sage

Good morning SN Community,

I have a requirement to create multiple release validation tasks using a UI action on the task form.  The script should allow for multiple requests to be created based on the selection of releases chosen in a field ('u_releases' so if there are 6 releases chosen, then 6 tasks should be created with each mapped to a release.). However, when I go to enact the UI action on the form, nothing happens. Can someone please tell me what I'm doing wrong? Here is my script: 

createNewRecords (); 

function createNewRecords() {
              if (typeof current.number != 'undefined' && current.number)
                             current.number = "";  //generate a new nunmber
              else if (typeof current.u_number != 'undefined' && current.u_number)
                             current.u_number = "";  //generate a new number
           

              var grParentRecordTable = new GlideRecord('x_namim_edrm_nos_erdm_releases');  //Release Table
              grParentRecordTable.addEncodedQuery('sys_idIN' + curent.u_releases.toString()); //List field of child releases
              grParentRecordTable.query();
              while (grParentRecordTable.next()) {
                             var grMassTasks = new GlideRecord('x_namim_edrm_nos_patch_schedule_task');  //Validation Task table
                             grMassTasks.initialize();
                             grMassTasks.release = grParentRecordTable.sys_id;
                             grMassTasks.signup = grParentRecordTable.u_mass_signup;  
                             grMassTasks.assignmentGroup = grParentRecordTable.assignment_group; 
                             grMassTasks.validationContact = grParentRecordTable.assigned_to;
                             grMassTasks.contact = grParentRecordTable.validation_contact_cell_number;
                            grMassTasks.ciName = grParentRecordTable.cmdb_ci;
                            grMassTasks.type = grParentRecordTable.validation_type;
                             grMassTasks.insert();
              }
              answer = current.insert();
}

1 ACCEPTED SOLUTION

Nya Valdez
Kilo Guru

Hello New Developer,

You can accomplish this by creating an array on the value you are using to create new records with. Also, when you are mapping fields to replicate across records, you will need to write it out as it is on the form as shown here:

     grMassTasks.u_mass_signup = current.u_mass_signup;

See my script below for that and let me know if you have any further questions. You should be able to do a copy / paste and test it out in your environment. 

(function(current) {

              var releases = current.u_releases.toString().split(',');             

              for (var i = 0; i < releases.length; i++) {
        grMassTasks = new GlideRecord('x_namim_edrm_nos_patch_schedule_task');
        grMassTasks.initialize();
        grMassTasks.parent = current.parent;
        grMassTasks.u_mass_signup = current.u_mass_signup;
        grMassTasks.assignment_group = current.assignment_group;
        grMassTasks.assigned_to = current.assigned_to;
        grMassTasks.validation_contact_cell_number = current.validation_contact_cell_number;
        grMassTasks.cmdb_ci = current.cmdb_ci;
        grMassTasks.validation_type = current.validation_type;
                             grMassTasks.u_releases = releases[i];

        grMassTasks.insert();
    }
})(current);

**Please mark my answer Correct or Helpful if applicable so that others may benefit if needed. 

View solution in original post

10 REPLIES 10

Nya, 

Thank you SOOOOO MUCH!!! This worked!!! It was exactly what I was looking for - THANK YOU!!!