- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2019 01:23 PM
Have a client that for Problem Task, they want they field changes that get logged in the Activity Stream copied up to the Activity Stream of the parent Problem ticket. I'm already copying the Work Notes and Comments up, but need to get the field changes. I've found where they are stored (sys_history_set), but from looking around posts, I don't see any other way to get the info other than from that table, or the audit table. Am I missing something?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2019 01:49 PM
Hello,
That's correct. It's for the focused table/audit table within that audit log. What you can do is also create an update Business Rule on the problem task table and have those changes "echo'd" up to the parent problem in the work notes section.
I.e.:
-technician updates problem task record short description field, state, and priority.
-the BR you setup on problem task with this code can write to parent
(function executeRule(current, previous /*null when async*/) {
var changeFields;
var gr = new GlideRecord('problem');
gr.addQuery('sys_id', current.problem);
gr.query();
if (gr.next()) {
for (var x in current){
if (current[x] != previous[x]) {
changedFields += 'Field ' + x + ' has changed on record ' + current.number + ' from ' + previous[x] + ' to ' + current[x] + '\n';
}
}
gr.work_notes = changedFields;
gr.update();
}
})(current, previous);
All in one work note, each entry on it's own line.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2019 01:49 PM
Hello,
That's correct. It's for the focused table/audit table within that audit log. What you can do is also create an update Business Rule on the problem task table and have those changes "echo'd" up to the parent problem in the work notes section.
I.e.:
-technician updates problem task record short description field, state, and priority.
-the BR you setup on problem task with this code can write to parent
(function executeRule(current, previous /*null when async*/) {
var changeFields;
var gr = new GlideRecord('problem');
gr.addQuery('sys_id', current.problem);
gr.query();
if (gr.next()) {
for (var x in current){
if (current[x] != previous[x]) {
changedFields += 'Field ' + x + ' has changed on record ' + current.number + ' from ' + previous[x] + ' to ' + current[x] + '\n';
}
}
gr.work_notes = changedFields;
gr.update();
}
})(current, previous);
All in one work note, each entry on it's own line.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2019 07:16 AM
I tried this and added a log statement to see what had changed. I went to a Problem Task and update about 3 fields, but the only thing that was logged was the sys_updated_on field.
(function executeRule(current, previous /*null when async*/) {
var changeFields;
var gr = new GlideRecord('problem');
gr.addQuery('sys_id', current.problem);
gr.query();
if (gr.next()) {
for (var x in current){
if (current[x] != previous[x]) {
gs.log('Field: ' + x);
changedFields += 'Field ' + x + ' has changed on record ' + current.number + ' from ' + previous[x] + ' to ' + current[x] + '\n';
}
}
gr.work_notes = changedFields;
gr.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2019 07:22 AM
Hi,
Can you try just using this to start and see what fields show as changed?
(function executeRule(current, previous /*null when async*/) {
for (var x in current){
if (current[x] != previous[x]) {
gs.addInfoMessage ('Field ' + x + ' has changed!' );
}
}
})(current, previous);
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2019 07:51 AM
Can you try
(function executeRule(current, previous /*null when async*/) {
var changedFields;
var gr = new GlideRecord('problem');
gr.addQuery('sys_id', current.problem);
gr.query();
while (gr.next()) {
for (var x in current){
if (current[x] != previous[x]) {
gs.log('Field: ' + x);
changedFields += 'Field ' + x + ' has changed on record ' + current.number + ' from ' + previous[x] + ' to ' + current[x] + '\n';
}
}
gr.work_notes = changedFields;
gr.update();
}
})(current, previous);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks