Usability - Productivity - Business - The web - Singapore & Twins

Update all views in a database - web style

It is a bad idea to check the property "hide from Notes client" on a view. If you do this you burden your HTTP task with refreshing that view rather than leaving that to the indexer task (which would run in its own thread on its own processor(s). The better way to hide views from Notes clients (for convenience) is to start their name with (. The Performance impact can be quite positive once you fix them (and bad if you don't). Until you get the approval and find the time to fix the view visibility a method is needed to quickly update all database views from a web perspective. In my toolbox there is a little script that does exactly that. The nice aspect of it: it lives in a utility database and takes the database to work on as a parameter:
http://mywebserver/senseitoolbox.nsf/webupdateviews?openAgent&database=apps/hr/webleave.nsf The agent renders a page with a link to each view in the database (I don't check for the "hide from web" property) and an Ajax call that opens ever view once through the URL and records completion. Completion doesn't imply success. I'm not monitoring for return codes or so. The agent is a good interim helper until the view visibility to the indexing task has been restored.
As usual YMMV
    Agent (webUpdateViews)
    Created Nov 23, 2010 by Stephan H Wissel/Singapore/IBM
    Description: Agent to refesh all views in the database using URL open

Option Public
Option Declare

Public Const queryStringName = "QUERY_STRING_DECODED"

Sub Initialize
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim workDB As NotesDatabase
    Dim doc As NotesDocument
    Set db = s. Currentdatabase
    Set doc = s. Documentcontext

    Dim dbNameItem As NotesItem
    Dim work As Variant 'For the evaluation of the database
    If Not doc. Hasitem (queryStringName ) Then
        Print "You need a querystring for this agent to work"
        Exit sub
    End If
    Set dbNameItem = doc. Getfirstitem (queryStringName )
    'Get the database name on the server
    work = Evaluate ( |@trim(@Left(@Right("|+dbNameItem. Text+ |&";"&database=");"&"))| )
    If work ( 0 ) = "" Then
        Print "You need to specify the database on the server with &database="
        Exit sub
    End If
    Set workDB = New NotesDatabase ( "",work ( 0 ) )
    If Not workDB. Isopen Then
        Call workDB. Open ( "", "" )
    End If
    If Not workDB. Isopen Then
        Print "Could not open the database "+work ( 0 )
        Exit sub
    End If
    Call RenderAjax (s, workDB )
End Sub

    Sub RenderAjax
    Description: Renders a HTML Page that goes nicely with Ajax

Sub RenderAjax (s As NotesSession, db As NotesDatabase )
    Dim out As NotesStream
    Dim script As NotesStream
    Dim url As String
    Dim curVurl As String
    Dim i As Integer
    Dim v As NotesView
    If db. Httpurl = "" Then
        url = "http://localhost/__"+db. Replicaid+ ".nsf/"
        url = db. Httpurl+ "/"
    End If
    Set out = s. Createstream ( )
    Set script = s. Createstream ( )
    Call script. Writetext ( |<script language="JavaScript" type="text/javascript">|,EOL_PLATFORM )
    Call addJSFunctions (script )
    Call out. Writetext ( "<h1>Auto Refresh for "+db. Filepath + "</h1>",EOL_PLATFORM )
    Call out. Writetext ( |<h2>|,EOL_PLATFORM )
    Call out. Writetext (url,EOL_PLATFORM )
    Call out. Writetext ( |</h2>|,EOL_PLATFORM )
    Call out. Writetext ( |<div id="result">Result</div>|,EOL_PLATFORM )
    Call out. Writetext ( |<ol>|,EOL_PLATFORM )
    i = 0
    ForAll curV In db. Views
        Set v = curV
        If Not v. Isfolder Then 'No point updating folders
            'This is just for the Show
            Call out. Writetext ( |<li><a href="| )
            If IsArray (v. Aliases ) then
                If v. Aliases ( 0 ) <> "" Then
                    curVurl = url + v. Aliases ( 0 )
                    curVurl = url + v. Name 
                End If
                curVurl = url + v. Name
            End If
            Call out. Writetext (curVurl )        
            Call out. Writetext ( |?Open">|+v. Name+ |</a>|,EOL_PLATFORM )
            Call out. Writetext ( |</li>|,EOL_PLATFORM )
            'This is the real work
            Call script. Writetext ( |views[|+ CStr (i )+ |] = "|+curVurl+ |";|,EOL_PLATFORM )
            i = i + 1
        End If
    End ForAll

    Call script. Writetext ( |callAllViews(0)|,EOL_PLATFORM )
    Call script. Writetext ( |</script>|,EOL_PLATFORM )
    Call out. Writetext ( |</ol>|,EOL_PLATFORM )
    'Now write out
    out. Position = 0
    Print out. Readtext ( )
    script. Position = 0
    Print script. Readtext ( )
End Sub

    Sub addJSFunctions
    Description: Adds all the JavaScript needed

Sub addJSFunctions (out As NotesStream )
Call out. Writetext ( |
    var views = [];
    function callAllViews(curIndex) {
        var r = createRequest();
        var resultEle = document.getElementsByTagName("LI");
        resultEle[curIndex].innerHTML += " - done";
        if (curIndex < views.length) {
        } else {
            // Here would be a check if that thing needs to run again

    function createRequest() {
        var request;
        try {
            request = new XMLHttpRequest();
            } catch (trymicrosoft) {
                try {
                    request = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (othermicrosoft) {
                    try {
                        request = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (failed) {
                        request = false;

        if (!request) {
            alert("Error initializing XMLHttpRequest!");

        return request;

End Sub

Posted by on 23 November 2010 | Comments (1) | categories: Show-N-Tell Thursday


  1. posted by Erik Brooks on Wednesday 24 November 2010 AD:
    Wow, this kinda stinks. Is there an SPR open for this? It seems like this should be fixed, or at least turned into an INI setting, e.g. UPDATE_UPDATE_HIDDEN_VIEWS=1