logo

NJP

Probably one of the best snippets on your Utils: getHistoryWalker

NOWJedi · Dec 09, 2022 · article

How many times did you write the code to find the previous value on a specific field? Long time ago I found a library called “HistoryWalker” and since then its been on my must-have snippets on my utils. This library sn_hw is not “public” available but you can see lot of scripts using it. Quite useful 🙂

    getHistoryWalker: function(grObject,field) {
        var answer = [];
        var previousValue;

        var hw = new sn_hw.HistoryWalker(grObject.getRecordClassName(), grObject.getUniqueValue());
        hw.walkTo(grObject.sys_mod_count);

        do {
            var wr = hw.getWalkedRecordCopy();
            var currentValue = wr.getValue(field);
            if (currentValue != previousValue) {
                previousValue = currentValue;
                answer.push(wr.getValue(field) + '');
            }
        } while (hw.walkBackward());

        return answer;
    },

The post Probably one of the best snippets on your Utils: getHistoryWalker appeared first on NOWJedi.

View original source

https://nowjedi.com/2022/12/09/probably-one-of-the-best-snippets-on-your-utils-gethistorywalker/