How to remove or replace a recordWatch?

Giles Lewis
Giga Guru

spUtil.recordWatch will add a watch on a set of records. But how do I remove the watch or replace it with a different filter?

1 ACCEPTED SOLUTION

Oleg
Mega Sage

It is not clear which scenario you try to implement. Do you use spUtil.recordWatch in your code or you try to modify or remove the watcher added by other port of code (not youth)?

If you use spUtil.recordWatch directly that I can suggest you the following solution. First of all you can open the page, which uses spUtil, open Developer Tools of Chrome and search for spUtil.js (press Ctrl-Shift-F, type spUtil.js and press Enter). By click on the item of the search results you will open the source code of spUtil.js. One more click on the Pretty Print button {} will make the code more readable:

find_real_file.png

As the result you can examine the code of spUtil.recordWatch

recordWatch: function($scope, table, filter, callback) {
    var watcherChannel = snRecordWatcher.initChannel(table, filter || 'sys_id!=-1');
    var subscribe = callback || function() {
        $scope.server.update()
    }
    ;
    watcherChannel.subscribe(subscribe);
    $scope.$on('$destroy', function() {
        watcherChannel.unsubscribe();
    });
},

and to see that you can use snRecordWatcher directly instead of usage spUtil.recordWatch. You will have watcherChannel, returned by snRecordWatcher.initChannel and you will be able to call watcherChannel.unsubscribe() to remove the watcher.

In the same ways you can search for snRecordWatcher.js and find and analyse the code of snRecordWatcher, which uses amb inside. Examining the code and debugging it you will be able to understand how it works and after that you will be able to implement scenario, which you need.

View solution in original post

1 REPLY 1

Oleg
Mega Sage

It is not clear which scenario you try to implement. Do you use spUtil.recordWatch in your code or you try to modify or remove the watcher added by other port of code (not youth)?

If you use spUtil.recordWatch directly that I can suggest you the following solution. First of all you can open the page, which uses spUtil, open Developer Tools of Chrome and search for spUtil.js (press Ctrl-Shift-F, type spUtil.js and press Enter). By click on the item of the search results you will open the source code of spUtil.js. One more click on the Pretty Print button {} will make the code more readable:

find_real_file.png

As the result you can examine the code of spUtil.recordWatch

recordWatch: function($scope, table, filter, callback) {
    var watcherChannel = snRecordWatcher.initChannel(table, filter || 'sys_id!=-1');
    var subscribe = callback || function() {
        $scope.server.update()
    }
    ;
    watcherChannel.subscribe(subscribe);
    $scope.$on('$destroy', function() {
        watcherChannel.unsubscribe();
    });
},

and to see that you can use snRecordWatcher directly instead of usage spUtil.recordWatch. You will have watcherChannel, returned by snRecordWatcher.initChannel and you will be able to call watcherChannel.unsubscribe() to remove the watcher.

In the same ways you can search for snRecordWatcher.js and find and analyse the code of snRecordWatcher, which uses amb inside. Examining the code and debugging it you will be able to understand how it works and after that you will be able to implement scenario, which you need.