Journal Activity are not visible (Incidents)

Mari2
Kilo Guru

Hello everyone

 

'm currently experiencing an issue with journal activities in the system.

Many incidents are missing their Activity History. When I click the filter icon, no filters are displayed at all. I’ve tested this by adding work notes, and I can confirm the entries are present in the sys_journal_field table. This issue appears to affect tickets assigned to specific groups. However, changing the assignment group does not resolve the problem.

 

Mari2_0-1754438699185.png

 

 

 

Mari2_1-1754438699188.png

 

 

For incidents where the issue does not occur, the activity filter appears as expected (see example below). Has anyone encountered this before or have any ideas on what might be causing it?

 

Mari2_2-1754438699191.png

 

 

 

1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @Mari2 ,

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB2185849

 

you do the following to resolve this

go to sys_journal_field table and filter with your record's sysid and find if there are any records with value looks empty and delete those

ChaitanyaILCR_0-1754440379743.png

go to sys_audit table and do the same find records with fields work_notes or comments new value is empty and delete those

ChaitanyaILCR_1-1754440551253.png

finally go the sys_history_set table and delete all the records related to that task record(this is for immediate effect)

ChaitanyaILCR_2-1754440622703.png

 

issue

Remove blank journal entries and all associated history sets. Removes sys audits, journal entries, and history sets. Removal is performed in chunks of 800 at a time, configurable by modifying the LIMIT constant.

A journal entry is considered to be blank if:
- It is empty
- It contains only whitespace characters
- It contains a single empty [code][/code] tag
- It contains a single [code][/code] tag containing only whitespace characters

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB2139855
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB2185849

or you can run below script as fix script or bg script to solve this thought out the instance

var LIMIT = 800;
var EMPTY_EXP = '^(\\[code]\\s*\\[/code])?$';

var SYS_AUDIT = 'sys_audit';
var SYS_JOURNAL_FIELD = 'sys_journal_field';

var TABLE_CONFIG = {};
TABLE_CONFIG[SYS_AUDIT] = {
    tableColumn: 'tablename',
    valueColumn: 'newvalue'
};
TABLE_CONFIG[SYS_JOURNAL_FIELD] = {
    tableColumn: 'name',
    valueColumn: 'value'
};

removeEmptyJournalEntries();

function removeEmptyJournalEntries(auditsComplete, journalsComplete) {
	var auditCount = auditsComplete ? 0 : removeChunk(SYS_AUDIT);
	var journalCount = journalsComplete ? 0 : removeChunk(SYS_JOURNAL_FIELD);

	if (auditCount === LIMIT || journalCount === LIMIT) {
		removeEmptyJournalEntries(auditCount < LIMIT, journalCount < LIMIT);
	}
}

function removeChunk(table) {
	return clean(
		collectChunkOfEmptyRecordIds(
			new Result(table),
			recordCreator(table)
		)
	);
}

function collectChunkOfEmptyRecordIds(result, createRecord) {
	collectEmptyRecordIds(result, createRecord("EMPTY"));

	if (result.size() < LIMIT) {
		collectEmptyRecordIds(result, createRecord("SPACE"));
	}

	if (result.size() < LIMIT) {
		collectEmptyRecordIds(result, createRecord("CODE"));
	}

	return result;
}

function collectEmptyRecordIds(result, record) {
	while (result.size() < LIMIT && record.nextValueIsEmpty()) {
		result.addSysId(record.getValue('sys_id'));
		result.addElementId(record.getValue('element_id'));
	}
}

function clean(result) {
    var size = result.size();

    if (size > 0) {
        var table = result.table;

        var tableCleaner = new GlideTableCleaner(table, 0);
        tableCleaner.setConditions('sys_idIN' + result.sys_id.join(','));
        tableCleaner.clean();

        if (table === SYS_JOURNAL_FIELD) {
            var historyCleaner = new GlideTableCleaner('sys_history_set', 0);
            historyCleaner.setConditions('idIN' + Object.keys(result.element_id).join(','));
            historyCleaner.clean();
        }
    }

    return size;
}

function recordCreator(table) {
	return function (type) {
		var config = TABLE_CONFIG[table];
		var record = new GlideRecord(table);

		if (table === SYS_AUDIT) record.addQuery('oldvalue', 'JOURNAL FIELD ADDITION');
		if (type === "CODE") record.addQuery(config.valueColumn, 'STARTSWITH', '[code]');
		if (type === "EMPTY") record.addEncodedQuery(config.valueColumn + "ISEMPTY^OR" + config.valueColumn + "=[code][/code]");
		record.orderBy(config.valueColumn);
		record.setLimit(LIMIT);
		record.query();

		return new Record(config, record);
	};
}

function Result(table) {
	this.element_id = {};
	this.sys_id = [];
	this.table = table;

	this.addSysId = function (id) { this.sys_id.push(id); };
	this.addElementId = function (id) { if (id) this.element_id[id] = true; };
	this.size = function () { return this.sys_id.length; };
}

function Record(config, record) {
	this.config = config;
	this.record = record;

	this.getValue = function (column) { return this.record.getValue(column); };
	this.nextValueIsEmpty = function () {
		return record.next() && (
			!this.record.getValue(this.config.valueColumn) ||
			this.record.getValue(this.config.valueColumn).trim().match(EMPTY_EXP)
		);
	};
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

View solution in original post

5 REPLIES 5

Thank you very much for your comment. Since not all incidents are affected, I wasn’t initially aware of when the issue started. However, the oldest journal entry with an empty Value field I found dates back to April 2020.