Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

capture the changes done in the Related lists on a form in Activity Formatter

YoungwooC
Tera Contributor

Hi community,


I am trying to capture changes made in the 'Contract CI' field, a related list field in the Contract (ast_contract) table. By default, additions to this related field are not tracked in the Activity History.

To address this, I created a Business Rule to generate a record in sys_history_line whenever a new entry is created in the Contract CI (contract_rel_ci) table. Although the Business Rule successfully creates entries in the sys_history_line table, these entries still do not appear in the Activity Formatter on the Contract form.

Is it possible to generate an Activity History log entry using a Business Rule when there is an addition to a related list field? If not, are there any recommended methods to ensure that changes in the Contract CI field are tracked and displayed in the Activity Formatter? or somewhere else?


(
function executeRule(current, previous /*null when async*/) {

    gs.log("Contract sys_id: "+current.contract);
    var fieldName = "work_notes";
    var contract = new GlideRecord('ast_contract');
    contract.addQuery("sys_id",current.contract);
    contract.query();
    if(contract.next()){
        var historySet = new GlideRecord('sys_history_set');
        historySet.addQuery("id",current.contract);
        historySet.query();
        if(historySet.next()){
            var historyLine = new GlideRecord('sys_history_line');
            var gdt = new GlideDateTime();
            historyLine.set = historySet.sys_id;
            historyLine.audit_sysid = '0';
            historyLine.field = 'relation';
            historyLine.label = 'relation';
            historyLine.type = 'relation';
            historyLine.update = -1;
            historyLine.user_id = 'admin';
            historyLine.old = 'Contract CI';
            historyLine.relation = 'Computer *DAVIN-IBM removed';
            historyLine.internal_checkpoint = 0;
            historyLine.update_time = gdt.getDisplayValueInternal();
            historyLine.user = admin's sys id;
            historyLine.user_name = 'System Administrator';
            historyLine.insert();
        }
})(current, previous);
0 REPLIES 0