How can we show fields changes to Activity streams

ST9
Tera Contributor

I want to show the field value changes from another table in activity stream.

Eg- In incident table i have referenced field( table= shipping details ) and any changes/update made in field from shipping details table should be captured in additional comments in Incident form.

1 ACCEPTED SOLUTION

Hi,

I tried the below sample of code to Update the incident worknotes whenever the caller (referencing the sys_user table is updated)

Note: In my case i have taken the reference table as "sys_user"

find_real_file.png

code as below:

var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name=sys_user^ORname=task^element!=NULL'); // Replace 'incident' by the table that is relevant to you
gr.query();
while (gr.next()) {
if (current[gr.element] != previous[gr.element])
if (gr['element'] != 'sys_mod_count' && gr['element'] != 'sys_updated_by' && gr['element'] != 'sys_updated_on') {  // refer screenshot below(pic -2) to understand why this condition is added
gs.addInfoMessage('Field ' + gr['name'] + '.' + gr.element + ' has changed!'); // Insert your here code to save log where you want
var a = 'Field ' + gr['name'] + '.' + gr.element + ' has changed!';
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', current.sys_id);
gr.query();
//gs.log("row counts::" + gr.getRowCount());  --- verify the row count before updating the record
while (gr.next()) {
gr.work_notes = a;
gr.update();
}
}

pic -2 :- when we update the record It takes "Updated", "Updated By" into consideration and hence in the above if condition we are excluding it....

find_real_file.png

Please change the table in your case to "shipping details" and replace the corresponding fields

View solution in original post

7 REPLIES 7

Bhavana Reddy
Mega Guru

if the value in the reference field changes or any field in the record from the shipping details is changed you want to update the incident comments?

Any fields in the record from shipping details is changed then update it in incident activity stream

ST9
Tera Contributor

HI Bhavana, Any clue?

Hi,

I tried the below sample of code to Update the incident worknotes whenever the caller (referencing the sys_user table is updated)

Note: In my case i have taken the reference table as "sys_user"

find_real_file.png

code as below:

var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name=sys_user^ORname=task^element!=NULL'); // Replace 'incident' by the table that is relevant to you
gr.query();
while (gr.next()) {
if (current[gr.element] != previous[gr.element])
if (gr['element'] != 'sys_mod_count' && gr['element'] != 'sys_updated_by' && gr['element'] != 'sys_updated_on') {  // refer screenshot below(pic -2) to understand why this condition is added
gs.addInfoMessage('Field ' + gr['name'] + '.' + gr.element + ' has changed!'); // Insert your here code to save log where you want
var a = 'Field ' + gr['name'] + '.' + gr.element + ' has changed!';
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', current.sys_id);
gr.query();
//gs.log("row counts::" + gr.getRowCount());  --- verify the row count before updating the record
while (gr.next()) {
gr.work_notes = a;
gr.update();
}
}

pic -2 :- when we update the record It takes "Updated", "Updated By" into consideration and hence in the above if condition we are excluding it....

find_real_file.png

Please change the table in your case to "shipping details" and replace the corresponding fields