- 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-05-2019 08:10 AM
Really close now. I've made a couple tweaks to Allen and Prateek's code, which are very similar.
Changed:
var changedFields;
to
var changedFields = '';
Don't know why that made a difference, but it did in the output. I had the word 'undefined' as the first item in the string. No biggy there.
Here is what I have so far and there's only 1 thing that needs to be done, get the actual label of the field instead of the field name.
Current output:
Field priority has changed on record PTASK0010192 from 4 - Low to 3 - Moderate
Field u_problem_task_type has changed on record PTASK0010192 from CAPA to Investigation
Field due_date has changed on record PTASK0010192 from 11/11/2019 10:13:05 to 11/12/2019 10:13:05
Current code:
(function executeRule(current, previous /*null when async*/) {
var changedFields = '';
var gr = new GlideRecord('problem');
gr.addQuery('sys_id', current.problem);
gr.query();
if (gr.next()) {
for (var x in current){
if (x != 'sys_updated_on' && x != 'sys_mod_count') {
if (current[x] != previous[x]) {
changedFields += 'Field ' + x + ' has changed on record ' + current.number + ' from ' + previous[x].getDisplayValue() + ' to ' + current[x].getDisplayValue() + '\n';
}
}
}
gr.work_notes = changedFields;
gr.update();
}
})(current, previous);
I tried using x.getLabel() to display the name, but it came back as undefined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2019 08:26 AM
Try
changedFields += 'Field ' + x + ' has changed on record ' + current.number + ' from ' + previous[x].getLabel() + ' to ' + current[x].getLabel() + '\n';
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2019 10:25 AM
They're similar because he copied your post with the code...which was copied from mine, lol.
He didn't create that on his own, but was helping tweak it.
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 11:46 AM
I wouldn't have cared if you asked to mark your answer as correct, but your reply seemed a bit odd, lol.
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2019 08:25 AM
Ok I got it. Found a response from Brad Tilton that got me down the right track:
Using current[x].getLabel() got me the field name. All is good now.
How do I share the glory with Allen A and Prateek Kumar as both of their answers got me down the right track?
