- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2025 07:47 AM
Hi guys!
I have a problem that concerns a custom table where templates have been created for users to configure general information when new records are made from these templates (table: x_vgll_decom_decommission_template).
On this template there is a field called 'log_close_notes_to', with three different values: 'system_info', 'analysis_existing' & 'information_analysis'.
In each x_vgll_decom_decommission_task record created under parent x_vgll_decom_decommission, there is a common 'close_notes' field. This close_notes field then writes data to the parent, in either the 'gathered_information', 'performed_analyses' or 'results_information_analyses' field on the parent (x_vgll_decom_decommission).
- So template "Investigate Existing Usage" (x_vgll_decom_decommission_template) with sys_id 30175f5c10520ad8ebb66a18cdd35b2f, 'analysis_existing' chosen,
should be mapped to field 'performed_analyses' on x_vgll_decom_decommission.
- Template "Investigate conditions" (x_vgll_decom_decommission_template) (connected has sys_id 12473e1c109ac6d8ebb66a18cdd35b2f, 'system_info' chosen, should be mapped to 'gathered_information' on x_vgll_decom_decommission.
- Template "Perform Information Analysis" (x_vgll_decom_decommission_template), has sys_id 5937179810d20ad8ebb66a18cdd35bff,
Remember that close_notes is a common field for all x_vgll_decom_decommission_task records and this is linked to the three different ones on the parent x_vgll_decom_decommission.
Here is a script that comes from a subflow activity that you can take inspiration from:
(function execute(inputs, outputs) {
var field = "";
if (inputs.log_section == 'system_info') {
field = 'gathered_information';
}
if (inputs.log_section == 'analysis_existing') {
field = 'performed_analyses';
}
if (inputs.log_section == 'information_analysis') {
field = 'results_information_analyses';
}
if (field != "") {
var decom = new GlideRecord('x_vgll_decom_decommission');
decom.get(inputs.decommission);
if (decom.isValidRecord()) {
var gdt = new GlideDateTime();
if (inputs.close_notes) {
var currVal = decom.getValue(field);
decom.setValue(field, '[' + gdt.getDisplayValue() + '] ' + inputs.short_description + ' : ' + (currVal ? currVal : '') + inputs.close_notes + '\n\n')
decom.update();
}
}
}
})(inputs, outputs);
Need to use this in the form of a Business Rule instead. The idea with the Business Rule is to be able to make changes to the documentation after closing a case. Currently, it is not possible after closing the case, as the flow is run once.
How would you create this business rule? My Business Rule does not work, this is how it looks like:
(function executeRule(current, previous /*null when async*/) {
var field = "";
switch (current.log_close_notes_to) {
case 'system_info':
field = 'gathered_information';
break;
case 'analysis_existing':
field = 'performed_analyses';
break;
case 'information_analysis':
field = 'results_information_analyses';
break;
}
if (field != "") {
var decom = new GlideRecord('x_vgll_decom_decommission');
decom.get(current.parent.sys_id);
if (decom.isValidRecord()) {
var gdt = new GlideDateTime();
if (current.close_notes) {
var currVal = decom.getValue(field);
decom.setValue(field, '[' + gdt.getDisplayValue() + '] ' + current.short_description + ' : ' + (currVal ? currVal : '') + current.close_notes + '\n\n');
decom.update();
}
}
}
})(current, previous);
And here is what I want to do, so when I write anything in this 'close_notes' field and save the task...
...this field should be updated with information below first timestamp:
Same goes for the two other task types.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 11:38 AM
That makes perfect sense now, thanks for pointing that out.
So instead of relying on log_close_notes_to directly on the task, we actually need to retrieve it from the referenced decommission_template.
The corrected approach: we will load the decommission_template record (from the task’s reference field), and then use its log_close_notes_to value to determine which field on the parent to update.
Updated Business Rule Code:
(function executeRule(current, previous) {
// Exit if there's no change to close_notes or no parent
if (!current.close_notes.changes() || !current.parent || !current.decommission_template) return;
// Get the template to determine where to log
var template = new GlideRecord('x_vgll_decom_decommission_template');
if (!template.get(current.decommission_template)) return;
var field = "";
switch (template.getValue('log_close_notes_to')) {
case 'system_info':
field = 'gathered_information';
break;
case 'analysis_existing':
field = 'performed_analyses';
break;
case 'information_analysis':
field = 'results_information_analyses';
break;
}
if (field !== "") {
var decom = new GlideRecord('x_vgll_decom_decommission');
if (decom.get(current.parent)) {
var gdt = new GlideDateTime();
var timestamp = '[' + gdt.getDisplayValue() + '] ';
var noteText = timestamp + current.short_description + ' : ' + current.close_notes + '\n\n';
var existing = decom.getValue(field) || "";
decom.setValue(field, existing + noteText);
decom.update();
// Optional: log it for debugging
gs.info(`[Decom Task BR] Appended close_notes to '${field}' on parent record ${current.parent}`);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2025 10:43 AM
Please try this, in the Business Rule:
Triggers on update of the x_vgll_decom_decommission_task table
Checks if the close_notes field has changed
Identifies the parent x_vgll_decom_decommission record
Determines which field (gathered_information, performed_analyses, results_information_analyses) to update
Appends the close notes with a timestamp and description
General Settings
Table: x_vgll_decom_decommission_task
When: after
Update: Yes
Insert: No
Delete: No
Advanced: Yes
Condition: Add this to ensure the rule runs only if close_notes has changed:
current.close_notes.changes() && current.close_notes
Script:
(function executeRule(current, previous) {
// Only continue if close_notes has changed and parent exists
if (!current.close_notes || !current.parent) return;
var field = "";
switch (current.log_close_notes_to) {
case 'system_info':
field = 'gathered_information';
break;
case 'analysis_existing':
field = 'performed_analyses';
break;
case 'information_analysis':
field = 'results_information_analyses';
break;
}
if (field !== "") {
var decom = new GlideRecord('x_vgll_decom_decommission');
if (decom.get(current.parent)) {
var gdt = new GlideDateTime();
var timestamp = '[' + gdt.getDisplayValue() + '] ';
var noteText = timestamp + current.short_description + ' : ' + current.close_notes + '\n\n';
var existing = decom.getValue(field) || "";
decom.setValue(field, existing + noteText);
decom.update();
}
}
})(current, previous);
Issue Fix / Note
current.parent.sys_id | Use current.parent directly — it auto-resolves the sys_id |
close_notes.changes() | Makes sure the logic doesn’t run every time unless the field changed |
setValue() formatting | Adds a timestamp and short description above each entry |
after rule | Important so the data is saved and available for update |
Prevent duplicate entries if the same note is edited repeatedly
Add current.state.changesTo("Closed") if you only want this to run when the task is closed
Add a gs.info() log line for audit/debug
Trigger an email notification to the task owner or approver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2025 03:58 AM
@SasiChanthati It didn't really work. The script somehow does not know when and what template is used in a task. There is a reference field on the 'x_vgll_decom_decommission_task' called 'decommission_template', which refers to 'x_vgll_decom_decommission_template' table, that I forgot to mention.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 11:38 AM
That makes perfect sense now, thanks for pointing that out.
So instead of relying on log_close_notes_to directly on the task, we actually need to retrieve it from the referenced decommission_template.
The corrected approach: we will load the decommission_template record (from the task’s reference field), and then use its log_close_notes_to value to determine which field on the parent to update.
Updated Business Rule Code:
(function executeRule(current, previous) {
// Exit if there's no change to close_notes or no parent
if (!current.close_notes.changes() || !current.parent || !current.decommission_template) return;
// Get the template to determine where to log
var template = new GlideRecord('x_vgll_decom_decommission_template');
if (!template.get(current.decommission_template)) return;
var field = "";
switch (template.getValue('log_close_notes_to')) {
case 'system_info':
field = 'gathered_information';
break;
case 'analysis_existing':
field = 'performed_analyses';
break;
case 'information_analysis':
field = 'results_information_analyses';
break;
}
if (field !== "") {
var decom = new GlideRecord('x_vgll_decom_decommission');
if (decom.get(current.parent)) {
var gdt = new GlideDateTime();
var timestamp = '[' + gdt.getDisplayValue() + '] ';
var noteText = timestamp + current.short_description + ' : ' + current.close_notes + '\n\n';
var existing = decom.getValue(field) || "";
decom.setValue(field, existing + noteText);
decom.update();
// Optional: log it for debugging
gs.info(`[Decom Task BR] Appended close_notes to '${field}' on parent record ${current.parent}`);
}
}
})(current, previous);