When I click NEW on my List Control to create new child tickets, it does not capture the Parent Case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 10:35 AM
Hi
I have 3 tables (Table 1, Table 2, and Table 3).
Table 1 uses a List Control that directs to Table 2 to create new records (they should be child records from table 1).
When I click NEW from table 1, it opens a form (form from table 2) to enter the information, and the information is actually created and store in Table 2. I have a business rule in table 2 that says "If field UUU says OOO create a new record in Table 3 which works, but Table 3 record does not have the Parent Case #.
I have a similar business rule that works, but that one uses a M2M table to collect the Parent Case.
Any suggestions?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 09:04 AM
Hi,
The code you posted looks like a Business Rule script. If so, the following is appropriate:
function executeRule(current, previous /*null when async*/ ) {
// var res = {};
var obtask = new GlideRecord("sn_observable");
obtask.addEncodedQuery("observable=" + current.sys_id);
obtask.orderBy("sys_created_on");
obtask.setLimit(1);
obtask.query();
if (obtask.next()) {
var resvalue = obtask.observable.value;
var restypeName = obtask.observable.type.name;
var resobSightingCount = obtask.observable.sighting_count;
var resobNotes = obtask.observable.notes;
var rescreatedBy = obtask.getValue("sys_created_by");
var restaskId = obtask.sys_id;
var resassignedToName = obtask.assigned_to.user_name;
var ressdesc = obtask.short_description;
var ressource = obtask.task.u_source.getDisplayValue();
var sit = new GlideRecord("sn_task");
var desc = "";
desc += "Incident Source System: " + res.source + "\n";
desc += "Value: " + resvalue + "\n";
desc += "Type: " + restypeName + "\n";
desc += "Incident Count: " + resobSightingCount + "\n";
desc += "Notes: " + resobNotes;
sit.initialize();
sit.setValue("parent", restaskId);
sit.setValue("priority", 3);
sit.setValue("assignment_group", "056ef4e01b9d34501123123123131321");
sit.setValue("assigned_to", "13123213213132321313");
sit.setValue("short_description", "False Positive Request");
sit.setValue("description", desc);
if (res.createdBy != "admin" && res.createdBy != "system") {
sit.setValue("affected_user", getUser(res.createdBy));
} else {
sit.setValue("affected_user", getUser(res.assignedToName));
}
sit.insert();
}
}
My guess is the 'res' Object is the problem. It is not not needed, and using variables for that is straight forward. Also, you're missing the final "}" for the function. And create the new table record inside the "if" code block. What happens if no record is found in the 'sn_observable' table?
Try the version here.