- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 12:09 PM
Hi guys!
I'm sitting with a custom table 'x_vgll_decom_decommission', which also has a child task table 'x_vgll_decom_decommission_task'.
On these child tasks there are several dotwalked fields from the parent. So the business requirement is that IF you make any update on the child table (the task), whether it is a dot-walked field from parent or a task field, "Status" ('state') should go from 1 (new) to 2 (in progress).
Is this possible?
I tried with this Before Update Business rule, With condition "State" Is "New" (1), which is not working:
(function executeRule(current, previous /*null when async*/) {
// Kontrollera att state är "Ny"
if (current.state != 1) return;
// Om decommission-referensen har ändrats, ladda båda parent-records
var decommissionChanged = current.decommission != previous.decommission;
var currentParent = current.decommission.getRefRecord();
var previousParent = new GlideRecord('x_vgll_decom_decommission');
if (!previousParent.get(previous.decommission.toString())) {
// Om parent inte kunde hämtas, hoppa över
return;
}
// Lista på parentfält att jämföra
var fieldsToCompare = [
'decommission_server_text',
'decommission_server',
'decommission_database_text',
'decommission_database',
'decommission_website_text',
'decommission_website',
'decommission_other_text',
'decommission_other',
'decommission_access_control_text',
'decommission_access_control',
'decommission_storage_text',
'decommission_storage',
'decommission_integrations_text',
'decommission_integrations',
'decommission_monitoring_text',
'decommission_monitoring',
'decommission_client_parts_text',
'decommission_client_parts',
'service_to_decommission'
];
var hasChanged = false;
for (var i = 0; i < fieldsToCompare.length; i++) {
var field = fieldsToCompare[i];
var currentVal = currentParent.getValue(field);
var previousVal = previousParent.getValue(field);
if (currentVal != previousVal) {
hasChanged = true;
break;
}
}
// Om något fält har ändrats, sätt state till Pågående (2)
if (hasChanged) {
current.state = 2;
}
})(current, previous);
With my faulty business rule, the state goes from 1 to 2 directly, upon insert (when new task record is created).
Any ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2025 05:50 AM
Ideally you should not allow updating dot walked fields as data for it resides at parent level.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 12:31 PM
Please try this.
(function executeRule(current, previous /*null when async*/) {
// Only run on update (not insert)
if (current.operation() !== 'update') return;
// Only act if state is 'New' (1)
if (previous.state != 1 || current.state != 1) return;
var hasChanged = false;
// Check if any *task-specific* field has changed
var taskFieldsToWatch = [
'short_description',
'description',
'assigned_to',
'due_date'
// Add other task-specific fields you care about
];
for (var i = 0; i < taskFieldsToWatch.length; i++) {
var f = taskFieldsToWatch[i];
if (current[f] != previous[f]) {
hasChanged = true;
break;
}
}
// Check if any parent field dot-walked to the task has changed
if (!hasChanged) {
var currentParent = current.decommission.getRefRecord();
var previousParent = new GlideRecord('x_vgll_decom_decommission');
if (previousParent.get(previous.decommission.toString())) {
var parentFieldsToCompare = [
'decommission_server_text',
'decommission_server',
'decommission_database_text',
'decommission_database',
'decommission_website_text',
'decommission_website',
'decommission_other_text',
'decommission_other',
'decommission_access_control_text',
'decommission_access_control',
'decommission_storage_text',
'decommission_storage',
'decommission_integrations_text',
'decommission_integrations',
'decommission_monitoring_text',
'decommission_monitoring',
'decommission_client_parts_text',
'decommission_client_parts',
'service_to_decommission'
];
for (var j = 0; j < parentFieldsToCompare.length; j++) {
var field = parentFieldsToCompare[j];
if (currentParent.getValue(field) != previousParent.getValue(field)) {
hasChanged = true;
break;
}
}
}
}
// If any relevant field changed, update state
if (hasChanged) {
current.state = 2; // In Progress
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2025 02:59 AM - edited ‎06-07-2025 03:39 AM
@folusho I realised I had another Business Rule active at the same time that spooked. But, your code works, only for native fields. When I change any dot-walked field, the state does not update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2025 05:26 AM
Thanks for letting me know and glad that it worked for you.
Please mark as kindly mark my reply as helpful so others can benefit from it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2025 05:50 AM
Ideally you should not allow updating dot walked fields as data for it resides at parent level.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader