• Global Profile

    By Dave Leigh 2 decades ago

    I've added Rob's CratchitCommonLibrary with modifications.



    The Global Profile (alias DBProfile) has a couple of neat features. Here's a screenshot:

    http://www.cratchit.org/VIC/Screenshots/GlobalProfile.png



    It's got some additional database entries to accommodate planned features (Products, Services, and Opportunities databases), and a column to indicate whether each is available. There are hotspots so you can point to your databases with the database picker, and you can reset the defaults. The default values assume that VIC is installed in your [Lotus\Notes\Data]VIC directory, as mine is.



    I've modified the PostSave() method to accommodate the new features. The modification is listed below and uses CratchitCommonLibrary. The change also copies the profile doc outright to the other database if it hasn't been initialized before. This is to make setup simpler, and removes the need to create a profile doc for each database.



    A modification to the Initialize script of CratchitCommonLibrary follows. This change opens the DBProfile for editing if this is our first time running VIC. All told, it's a much cleaner first run than what I had originally (using environment variables), and thanks to Rob for making that possible.



    ==================



    Sub Postsave(Source As Notesuidocument)

    %REM

    Pushes the changes to all of the other databases.

    Author: Rob Breault.

    Modified by: Dave Leigh.

    Changes:

    2004-11-19: DFL: Replaced all dbs(x) with dbName(x) and build the field names.

    This gives us the ability to control whether any individual database is active.

    (for forward compatibility with Products, Services and Opps databases)

    %END REM

    Dim target_db As NotesDatabase  <br/>
    Dim doc As NotesDocument, profile_doc As NotesDocument  <br/>
    Dim dbName(6) As String <br/>
    Dim dbs(6) As String  <br/>
    Dim sDbFieldName As String ' holds the field name that describes the database<br/>
    Dim sInstFieldName As String ' holds the name of the installed field.<br/>
    Dim sDbField As String ' what's the database's name?<br/>
    Dim sInstalled As String ' is this database installed?<br/>
    Dim x As Integer  <br/>
    Set doc = source.Document  <br/>
    <br/>
    ' What databases do we support?<br/>
    dbName(0) = &quot;Contracts&quot;<br/>
    dbName(1) = &quot;Rolodex&quot;<br/>
    dbName(2) = &quot;Journal&quot;<br/>
    dbName(3) = &quot;Library&quot;<br/>
    dbName(4) = &quot;Products&quot;<br/>
    dbName(5) = &quot;Services&quot;<br/>
    dbName(6) = &quot;Opportunities&quot;<br/>
    <br/>
    ' check each one.<br/>
    For x = 0 To Ubound(dbName)  <br/>
        ' what fields will we look at?      <br/>
        sDbFieldName = &quot;Profile&quot; + dbName(x) + &quot;Name&quot;<br/>
        sInstFieldName = &quot;Profile&quot; + dbName(x) + &quot;Installed&quot;<br/>
        ' get their values<br/>
        sDbField = doc.GetItemValue(sDbFieldName)(0)<br/>
        sInstalled = doc.GetItemValue(sInstFieldName)(0)<br/>
        <br/>
        ' if the database defined AND installed, then push to it.<br/>
        If sDbField &lt;&gt; &quot;&quot; And sInstalled &lt;&gt; &quot;&quot; Then  <br/>
            Set target_db = session.GetDataBase(this_db.Server, sDbField, False)  <br/>
            If Not (target_db Is Nothing) Then  <br/>
                Set profile_doc = target_db.GetProfileDocument(&quot;DBProfile&quot;)<br/>
                If profile_doc Is Nothing Then<br/>
                    ' copy the profile doc outright to the target directory<br/>
                    Call doc.CopyToDatabase(target_db)<br/>
                Else<br/>
                    ' remove all of the form-defined variables (clear the target)<br/>
                    Forall item In profile_doc.Items  <br/>
                        If Left$(item.Name,1) &lt;&gt; &quot;$&quot; Then Call item.Remove  <br/>
                    End Forall  <br/>
                    ' update from this one.<br/>
                    Call doc.CopyAllItems(profile_doc,True)  <br/>
                    Call profile_doc.Save(True,False,True)  <br/>
                End If<br/>
            End If  <br/>
        End If  <br/>
    Next x  <br/>
    

    End Sub



    =============================



    Sub Initialize

    %REM

    Pushes the changes to all of the other databases.

    Author: Rob Breault.

    Modified by: Dave Leigh (DFL)

    Changes:

    2004-11-19: DFL: Create and edit the profile if it doesn't exist.

    %END REM

    On Error Goto ErrorHandler<br/>
    Set session = New NotesSession<br/>
    Set ws = New NotesUIWorkspace<br/>
    Set this_db = session.CurrentDatabase<br/>
    Set profile_doc = this_db.GetProfileDocument(&quot;DBProfile&quot;)<br/>
    crlf = Chr$(10) &amp; Chr$(13)<br/>
    If profile_doc.ProfileConfigName(0) = &quot;&quot; Then<br/>
        Msgbox &quot;VIC has not been previously setup, please do so now.&quot;<br/>
        Call ws.EditProfile(&quot;DBProfile&quot;)<br/>
    Else<br/>
        Set config_db = session.GetDatabase(this_db.Server, profile_doc.ProfileConfigName(0), False)<br/>
        If config_db Is Nothing Then Error 10001, |Configuration database not found: | &amp; profile_doc.ProfileConfigName(0)<br/>
        Set rolodex_db = session.GetDatabase(this_db.Server, profile_doc.ProfileRolodexName(0), False)<br/>
        If rolodex_db Is Nothing Then Error 10002, |Rolodex database not found: | &amp; profile_doc.ProfileRolodexName(0)<br/>
        Set contracts_db = session.GetDatabase(this_db.Server, profile_doc.ProfileContractsName(0), False)<br/>
        If contracts_db Is Nothing Then Error 10003, |Contracts database not found: | &amp; profile_doc.ProfileContractsName(0)<br/>
        Set journal_db = session.GetDatabase(this_db.Server, profile_doc.ProfileJournalName(0), False)<br/>
        If journal_db Is Nothing Then Error 10004, |Journal database not found: | &amp; profile_doc.ProfileJournalName(0)<br/>
        Set library_db = session.GetDatabase(this_db.Server, profile_doc.ProfileLibraryName(0), False)<br/>
        If library_db Is Nothing Then Error 10005, |Library database not found: | &amp; profile_doc.ProfileLibraryName(0)<br/>
    End If<br/>
    

    ExitSub:

    Exit Sub<br/>
    

    ErrorHandler:

    Msgbox &quot;ERROR &quot; &amp; Err &amp; &quot;: &quot; &amp; Error &amp; &quot; on line &quot; &amp; Erl<br/>
    Resume ExitSub<br/>
    

    End Sub