Create Multiple Records using UI action based on Field Value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 09:03 AM
Hello SN Community,
I am working on a requirement to create multiple records using a UI action, based on a field value. The field value is a location field (u_locations) which can contain any number of entries listed. What should happen is if there are 7 locations listed in u_locations, then 7 incidents should be created - one for each location. What I am getting is one duplicate record that has the same number (the number should be different) rather than 7 records. Can someone please tell me what I'm doing wrong? Here is my script:
doNewRecords ();
answer = current.insert();
gs.include('ActionUtils');
var au = new ActionUtils();
function doNewRecords() {
var saveMe = current;
var count = 0;
var grChildRecordTable = new GlideRecord('u_operational_mechanical_incident');
// grChildRecordTable.addEncodedQuery('sys_idIN' + current.u_releases.toString());
grChildRecordTable.addEncodedQuery('sys_idIN' + current.u_locations.toString());
grChildRecordTable.query();
while (grChildRecordTable.next()) {
count++;
var grNewTaskTable = new GlideRecord('u_operational_mechanical_incident');
grNewTaskTable.initialize();
grNewTaskTable.release = grChildRecordTable.sys_id;
grNewTaskTable.dataHalls = grChildRecordTable.u_locations;
grNewTaskTable.incidentType = grChildRecordTable.u_incident_type;
grNewTaskTable.start = grChildRecordTable.u_start_date;
grNewTaskTable.report = grChildRecordTable.u_report_date;
grNewTaskTable.caller = grChildRecordTable.caller_id;
grNewTaskTable.description = grChildRecordTable.description;
grNewTaskTable.insert();
}
au.postInsert(current);
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 10:47 AM
Hi Aman,
The part that I need assistance with is getting my script to see how many entries are in the u_locations field, and create that number of records when the UI action is engaged. Please advise.
