- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 08:25 AM
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();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 09:56 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 09:13 AM
Hmm... interesting.
Let's see if can break this down.
1. Are there conditions? If so, do the conditions satisfy for the script to execute?
2. Is the gliderecord object grParentRecordTable able to find any records after the query? (A getRowCount() would confirm that)
3. Sometimes the devil is toString():
Add .toString() to all your assignments, for example:
grMassTasks.release = grParentRecordTable.sys_id.toString();
4. And lastly, I have a faint gut-feeling typeof could be the culprit.
Could you comment your if and elseif conditions at the top and try?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 10:48 AM
Hello AnirudhKumar,
These are the conditions on the UI action: current.canCreate() && current.getTableName() == "x_namim_edrm_nos_patch_schedule_task"
I checked to see if there are records found and there are.
I added .toString to my assignments and commented out the type of / else if statements
When I created a new record and enacted the Mass Sign Up UI action, nothing happened again ...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 03:11 PM
Ok, last try.
Which scope is the UI Action in - Is it the same as the one in which the table x_namim_edrm_nos_patch_schedule_task was created?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 03:49 PM
Yes, they are in the same scope. In fact, it is a scoped application and I've built the UI action within Studio app. I also added some logging and the script goes all the way to the end and the messages appear in the log files but there are no error messages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 09:56 AM
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.