TexasSwede
texasswede@gmail.com
  • About this blog
  • My Website
  • My Resume
  • XML Export Tool
  • Photos

Category Archives: IBM/Lotus

Which is faster, ColumnValues() or GetItemValue()?

Posted on February 4, 2013 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino, Programming 3 Comments

In a recent discussion thread in one of the forums on IBM developerWorks, the issue of which is faster, doc.GetItemValue() or viewentry.ColumnValues(). I decided to test this, using two Lotusscript agents, created to be as similar as possible, working against the same view of the same database.

First, here is Agent #1, using ColumnValues() to get the value we are looking for from the first column of the view. This agent took 66.3 seconds to run, and below you can see exactly how that time was spent:

Agent #1 - Using ColumnValues()

 

And this is Agent #2, identical to Agent #1, except two lines, first getting the NotesDocument from the view entry, and then using GetItemValue() to get the value out of the document. This agent took 225.8 seconds to run:

Agent # 2 -_GetItemValue()

In both agents, the call to get the next document in the ViewEntryCollection takes about 60 seconds. As you can see, the 30,000 calls to GetColumnValues() in agent #1 takes pretty much no time — 1.3 seconds — while it takes 133 seconds to open the 30,000 documents and read the value of the field from each one in agent #2. Almost exactly 100 times longer!

In agent 2, you also have to add 26 seconds to get the NotesDocument object from the ViewEntry object.

I hope this settles the discussion.

 

Lotusphere/Connect 2013

Posted on February 3, 2013 by Karl-Henry Martinsson Posted in IBM/Lotus, Lotusphere, Technology Leave a comment

I have not been blogging here during Lotusphere/Connect 2013. It was a very busy conference, I went to a large number of sessions, and also many social gatherings of different kinds. In addition, I have been blogging at SocialBizUG.org, and if you don’t have an account there, go get on. If you already are a member of LotusUserGroup.org, your login credentials from there should work.

Below are links to my blog entries at that site. Enjoy!

Day 1 – Sunday

Day 2 – Opening General Session

Day 2 – Monday

Day 3 – Tuesday

Day 4 – Wednesday

Day 5 – Thursday

I also want to share the traditional yearly blogger picture on the Lotusphere stage:

The Blogger Community in the traditional Lotusphere picture. Photo by John Roling, used with permission.

The Blogger Community in the traditional Lotusphere picture.
Photo by John Roling, used with permission.

 

Preparing for Connect 2013

Posted on January 19, 2013 by Karl-Henry Martinsson Posted in Lotusphere Leave a comment

As I posted yesterday, I am able to go to Connect/Lotusphere after all. I now have to rush my preparations. I got a flu shot yesterday duing lunch, and I am about to head out to get my Lotusphere haircut shortly. I also need to pick up another pair of walking shoes and some other items for the trip.

This is the first Connect (if you don’t count last year, where that was a small conference within the conference), so we are all technically “first timers”, but if you haven’t been to Lotusphere in the past, I wrote an article for SocialBizUG.org (formerly LotusUserGroup.org) with some useful tips for first time attendees. You can read it here.

In just 7 days I will be sitting on a plane heading to MCO. I can’t wait.

Good News – Going to Connect/Lotusphere after all!

Posted on January 18, 2013 by Karl-Henry Martinsson Posted in Lotusphere Leave a comment

Thanks to some good luck, I will be able to afford to pay my way and attend Connect in just over a week.
I found a decent air fare (they have been going up every date for the last couple of days), and I will be arriving at MCO on Saturday at 2.10pm. That should make me show up at BALD around 3.30pm or so, just in time for a late lunch and a after-travel beer. I am heading back home Friday at 7.40pm, giving me time to do a little bit of shopping at the LEGO store at Downtown Disney after the conference…

I have had several people offer me to share/split their rooms, and I want to thank everyone that been trying to help me out. This is what the Lotus community is all about, helping each other. I hope I will be able to repay this in some way in the future.

I am looking forward to seeing all my old friends, and to hopefully make some new ones. See you in Orlando in 8 days!

Dolphin Hotel

 

No Connect/Lotusphere for me this year…

Posted on January 11, 2013 by Karl-Henry Martinsson Posted in Lotusphere Leave a comment

I just got word from my boss that I will not be able to go to Connect 2013 in Orlando. This is due to financial reasons, the company is trying to save money anywhere they can. Even as the conference would only cost them $3,200 (I found a really good airfare and got offers to share a room), it was not approved (not even after I offered to pay part of the cost myself).

This will be the first time since I started going in 1998 that I won’t be in Orlando to learn new things, network and meet all my friends in the Yellowverse. This would actually have been my 17th Lotusphere (I also attended Lotusphere Europe in 1996). I am of course very disappointed, but it happens. I hope to be able to go next year, and possibly attend IamLUG or some other conference later this year.

I will be following the event through twitter and Facebook, and hopefully there will be some videos uploaded during/after the conference. Have a beer for me, and enjoy the conference. And keep the blog posts and twitter messages coming!

Code: Expanded Class for File Functions

Posted on December 21, 2012 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino, Programming Leave a comment

Yesterday I blogged about a simple class to parse file names, and that inspired me to improve it and add some functionality, which will actually come in handy for a project at work shortly.

The class is pretty self-explanatory, there is really nothing complicated in the code.
When the class is initialized, if a path to a directory (i.e. ending with \) is passed to the constructor the directory is created if it does not exist. If the directory exist, there are functions to copy or move both single files or all files in the directory. Directories can also be deleted using the RemoveDir method.
In addition, there are properties to get the path, file name, extension and file size (in bytes) of the file (if the class was initialized with a file name).

Here is an agent with some examples of how to call the class:

Option Public
Option Declare
Use "Class.FileFunctions"

Sub Initialize
  Dim file As FileObject
  Dim cnt As Integer
  Dim success As Boolean 

  '*** Create new file object
  Set file = New FileObject("D:\Downloads\Downloads\MERP\Assassins of Dol Amroth.pdf")

  '*** Copy the file to another (new) directory
  Call file.CopyTo("D:\Downloads\MERP1\", file.FileName)

  '*** Move the file to a new location and replace space with + in file name
  Call file.MoveTo("D:\Downloads\MERP2\", Replace(file.FileName," ","+"))

  '*** Create a new directory if it does not exist
  Set file = New FileObject("D:\Downloads\MERP3\Test\")

  '*** Copy all files in specified directory to another directory
  Set file = New FileObject("D:\Downloads\Downloads\MERP\")
  cnt = file.CopyAllTo("D:\Downloads\MERP\Backup\")
  MsgBox "Copied " & cnt & " files."

  '*** Move all files in the previously specified directory to another location
  cnt = file.MoveAllTo("D:\Downloads\Middle-Earth Role Playing Game\")
  MsgBox "Moved " & cnt & " files."

  '*** Remove D:\Downloads\Downloads\MERP\
  Call file.RemoveDir("")

  '*** Remove D:\Downloads\MERP3\ and Test directory that we created earlier
  success = file.RemoveDir("D:\Downloads\MERP3\Test\")
  If success = True Then
    success = file.RemoveDir("D:\Downloads\MERP3\")
    If success = False Then
      MsgBox "Failed to delete D:\Downloads\MERP3\"
    End If
  Else
    MsgBox "Failed to delete D:\Downloads\MERP3\Test\"
  End If
End Sub

 

Below is the class itself, I put it in a script library called Class.FileFunctions.

%REM
  Copyright (c) Karl-Henry Martinsson 2012.
  Some code copyright Andre Guirard (see below).
  You are free to use and modify my code, as long as you keep
  all copyright info intact. If you improve the code, please
  consider sharing it back to the community.
%END REM

Option Public
Option Declare

Type FileDetails
  path As String
  filename As String  
  extension As String
  filesize As Long
End Type

Class FileObject
  Private file As FileDetails
  Public silent As Boolean
  
  Public Sub New(filepathname As String)
    silent = False
    FullPathName = filepathname
    If file.FileName = "" Then
      If file.Path <> "" Then
        On Error 76 GoTo parentDoesNotExist 
        'No filename but path, then we create that directory (if missing)
        If Dir$(file.Path,16)="" Then
createDirectory:  
          Call MakeDir(file.Path)
        End If
      End If
      file.FileSize = 0 
    Else
      file.FileSize = FileLen(filepathname)
    End If
    Exit Sub
parentDoesNotExist:          
    Resume createDirectory  
  End Sub
  
  
  Public Property Set FileName As String
    file.FileName = FileName
    file.Extension = StrRightBack(FileName,".")
  End Property
  
  Public Property Get FileName As String
    FileName = file.FileName  
  End Property
  
  
  Public Property Get Extension As String
    Extension = file.Extension  
  End Property
  
  Public Property Set Extension As String
    file.Extension = Extension   
  End Property
  
  
  Public Property Set FilePath As String
    file.Path = FilePath  
    If Right(file.Path,1)<>"\" Then
      file.Path = file.Path & "\"
    End If
  End Property
  
  Public Property Get FilePath As String
    FilePath = file.Path  
  End Property
  
  
  Public Property Set FullPathName As String
    Me.FilePath = StrLeftBack(FullPathName,"\")
    Me.FileName = StrRightBack(FullPathName,"\")
  End Property
  
  Public Property Get FullPathName As String
    FullPathName = file.Path & file.FileName  
  End Property
  
  
  Public Function CopyTo(ByVal newpath As String, ByVal newname As String) As Boolean
    '*** Check if both arguments are blank, then exit
    If FullTrim(newpath) = "" Then
      If FullTrim(newpath) = "" Then
        CopyTo = False
        Exit Function
      End If   
    End If
    If FullTrim(newpath) = "" Then
      newpath = file.Path
    End If  
    If FullTrim(newname) = "" Then
      newname = file.FileName 
    End If  
    Call MakeDir(newpath)
    On Error GoTo errHandlerCopyTo
    FileCopy me.FullPathName, newpath + newname
    If silent = False Then
      Print "Copied " & filename & " from " & file.Path & " to " & newpath
    End If
    CopyTo = True
exitFunctionCopyTo:
    Exit Function
errHandlerCopyTo:
    CopyTo = False
    Resume exitFunctionCopyTo
  End Function
  
  
  Public Function MoveTo(ByVal newpath As String, ByVal newname As String) As Boolean
    '*** Check if both arguments are blank, then exit
    If FullTrim(newpath) = "" Then
      If FullTrim(newpath) = "" Then
        MoveTo = False
        Exit Function
      End If   
    End If
    If FullTrim(newpath) = "" Then
      newpath = file.Path
    End If  
    If FullTrim(newname) = "" Then
      newname = file.FileName 
    End If
    Call MakeDir(newpath)
    On Error GoTo errHandlerMoveTo
    FileCopy me.FullPathName, newpath + newname
    Kill me.FullPathName
    If silent = False Then
      Print "Moved " & filename & " from " & file.Path & " to " & newpath
    End If
    
    MoveTo = True
exitFunctionMoveTo:
    Exit Function
errHandlerMoveTo:
    MoveTo = False
    Resume exitFunctionMoveTo
  End Function


  Public Function CopyAllTo(ByVal newpath As String) As Integer
    Dim filename As String
    Dim filecount As Integer
    '*** Check if both arguments are blank, then exit
    If FullTrim(newpath) = "" Then
      If FullTrim(newpath) = "" Then
        CopyAllTo = 0
        Exit Function
      End If   
    End If
    If FullTrim(newpath) = "" Then
      newpath = file.Path
    End If  
    Call MakeDir(newpath)
    On Error GoTo errHandlerCopyAllTo
    filename = Dir$(file.Path,2)  ' Include hidden files
    Do until filename=""
      FileCopy file.Path + filename, newpath + filename
      If silent = False Then
        Print "Copying " & filename & " from " & file.Path & " to " & newpath
      End If
      filecount = filecount + 1
      filename = Dir$()
    Loop
    CopyAllTo = filecount
exitFunctionCopyAllTo:
    Print "Copied " & filecount & " files"
    Exit Function
errHandlerCopyAllTo:
    CopyAllTo = filecount
    Resume exitFunctionCopyAllTo
  End Function

  Public Function MoveAllTo(ByVal newpath As String) As Integer
    Dim filename As String
    Dim filecount As Integer
    Dim deletelist List As String
    '*** Check if both arguments are blank, then exit
    If FullTrim(newpath) = "" Then
      If FullTrim(newpath) = "" Then
        MoveAllTo = 0
        Exit Function
      End If   
    End If
    If FullTrim(newpath) = "" Then
      newpath = file.Path
    End If  
    Call MakeDir(newpath)
    On Error GoTo errHandlerMoveAllTo
    filename = Dir$(file.Path,2)  ' Include hidden files
    Do Until filename=""
      FileCopy file.Path + filename, newpath + filename
      If silent = False Then
        Print "Moving " & filename & " from " & file.Path & " to " & newpath
      End If
      deletelist(filename) = file.Path + filename
      filecount = filecount + 1
      filename = Dir$()
    Loop
    Print "Cleaning up..."
    ForAll f In deletelist
      Kill f  
    End ForAll
    MoveAllTo = filecount
exitFunctionMoveAllTo:
    Print "Moved " & filecount & " files"
    Exit Function
errHandlerMoveAllTo:
    MoveAllTo = filecount
    Resume exitFunctionMoveAllTo
  End Function

  Public Function RemoveDir(ByVal dirpath As String) As Boolean
    '*** If blank, use the path in object
    If FullTrim(dirpath) = "" Then
      dirpath = file.path
    End If
    On Error GoTo errHandlerRemoveDir
    RmDir dirpath
    RemoveDir = True
exitRemoveDir:        
    Exit Function
errHandlerRemoveDir:
    RemoveDir = False
    Resume exitRemoveDir
  End Function
  

  ' ===== Private Supporting Functions =====  
  
  Private Sub MakeDir(Byval strWhere As String)
    ' *** This code by Andre Guirard @ IBM
    ' *** http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/recursive-mkdir-vs.-iteration
    ' *** Using an iterative method instead of recursive due to stack issues (see link above)
    On Error 76 Goto parentDoesNotExist 
    Dim stack$ 
    Const NL = { 
} 
    Do 
      Mkdir strWhere 
      On Error Goto 0 ' first success, stop trapping errors; avoid infinite loop. 
      strWhere = Strleft(stack, NL) ' "pop" a path for next iteration 
      stack = Mid$(stack, Len(strWhere)+2) 
failed: 
    Loop Until strWhere = "" 
    Exit Sub 
parentDoesNotExist: 
       ' This error code can indicate other problems, but assume missing parent. 
       ' If not, we get a different error (75) later when trying to create the parent. 
    Dim fpath$, fname$ 
    SplitFilepath strWhere, fpath, fname 
    If fpath = "" Then Error 76, "Invalid path: '" & strWhere & "'" 
    stack = strWhere & NL & stack ' "push" onto stack to retry later. 
    strWhere = fpath ' try a path one step shorter. 
    Resume failed 
  End Sub 

  
  Private Sub SplitFilePath(Byval fullpath$, dirpath$, filename$) 
    ' *** This subroutine by Andre Guirard @ IBM
    ' *** http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/recursive-mkdir-vs.-iteration
    ' *** Called from MakeDir()    
    Const DELIMS = {/\:} 
    While Instr(DELIMS, Right$(fullPath, 1)) ' discard final delimiter character... 
      fullpath = Left$(fullpath, Len(fullpath)-1) 
    Wend 
    Dim candidate$, i% 
    filename = Strtoken(fullpath, Left$(DELIMS, 1), -1) 
    For i = 2 To Len(DELIMS) 
      candidate = Strtoken(fullpath, Mid$(DELIMS, i, 1), -1) 
      If Len(candidate) < Len(filename) Then 
        filename = candidate 
      End If 
    Next 
    Dim fplen% 
    fplen = Len(fullpath)-Len(filename) 
    If fplen > 0 Then fplen = fplen - 1 
    dirpath = Left$(fullpath, fplen) 
  End Sub
  
End Class

 
Enjoy!
 

IBM Notes & Domino 9.0 Social Edition – Public beta now available!

Posted on December 13, 2012 by Karl-Henry Martinsson Posted in IBM/Lotus, Notes/Domino Leave a comment

Today, one day before the day previously mentioned, IBM have made the public beta of IBM Notes and Domino 9.0 Social Edition available for download. This is perhaps because of the fact that tomorrow is the opening day here in the US for The Hobbit, and IBM figured that all us geeks will go watch that instead of playing with the latest version of Notes.

This is what IBM says about the new version:

IBM Notes and Domino 9.0 Social Edition Public Beta isa preview of the next release of Notes, iNotes, Domino Designer, Domino and Notes Traveler. IBM Notes and Domino software puts you on a solid path to becoming a social business. IBM Notes and Domino 9.0 Social Edition Public Beta provides significant new social capabilities including :

  • Activity streams: allow you to view and take action quickly on content and events
  • Embedded Experiences: allow you to access business critical actions from other applications without leaving your email. This brings collaboration in-context and results in tighter integration across iNotes, Connections, Notes, app dev (XPages), and 3rd-party products and services
  • Contemporary user interface, simpler navigation, easier to locate information both in Notes and iNotes
  • IBM Notes Browser Plug-in: allows rapid delivery of IBM Notes Social Edition applications to the web
  • Incorporation of a social application container, based on the OpenSocial standard, which provides for development of a reusable set of “gadgets” from both IBM and third parties
  • Inclusion of the XPages Extension Library which greatly improves developer productivity when building collaborative workflow driven applications for web, mobile web and Notes
  • Domino Designer provides a new home page, editor enhancements and a server-side JavaScript debugger for use with XPages
  • Enhancements to Domino REST services and new Calendaring and Scheduling APIs
  • Domino integration: SAML, OAuth
  • Notes Traveler: Windows Phone 7.5/8; BlackBerry 10 BES support; IBM i Server

There are already some screenshots available online, and I plan to look closer at the product over the weekend and next week. I am currently downloading the 2GB of files I need…

Downloading Notes & Domino 9.0

Show and Tell – Dynamic Web Calendar

Posted on November 27, 2012 by Karl-Henry Martinsson Posted in Frameworks, IBM/Lotus, Javascript, Lotusscript, Notes/Domino, Programming, Web Development 1 Comment

In this post in the developerWorks forum, Andy Herlihy is asking about how to create a small calendar that can be embedded into an existing intranet website. As Carl Tyler points out, Andy could simply use Dojo.

However, this is a good example to show some jQuery combined with the power of IBM Lotus Domino.  Lets’ break it down into a few smaller steps.

The first one is to create a Domino web agent that will take the current date and build a calendar for that month. There will be no links or javascript code in the HTML generated, just plain HTML code, with some id attributes to make it easy to address different cells later.

The next step is to create a very simple webpage, with some Javascript to load jQuery and set up the calendar to detect clicks. The clicks will cause another call to the Domino server, this time to a view using RestrictToCategories to only get the entries for the specified date. The entries are returned as HTML and through jQuery they are displayed in a div on the webpage. We also want to add a little bit of CSS to make the calendar pretty. The CSS also lives on the HTML page.

Finally we create the view, it’s associated view template form and a form to create some entries that we can use for testing.

 

Let’s look at the code. First the Domino web agent. It should be pretty self explanatory:

%REM
    Agent WebCalendar
    Created Nov 26, 2012 by Karl-Henry Martinsson/Deep-South
    Description: Returns HTML for a calendar for current month
%END REM
Option Public
Option Declare

Sub Initialize
    '*** Used to get URL params
    Dim session As New NotesSession
    Dim webform As NotesDocument
    Dim urlstring As String
    Dim urlarr As Variant
    Dim urlvaluename As Variant
    Dim urldata List As String
    Dim webservername As String
    '*** Agent specific
    Dim startDate As NotesDateTime
    Dim endDate As NotesDateTime
    Dim i As Integer
    Dim j As Integer
    Dim startweekday As Integer
    Dim thisMonth As Integer
    Dim currDate As Double
    Dim cellclass As String

    Set webform = session.DocumentContext
    '*** Calculate path for this database, for image/icon file references later
    webservername = webform.GetItemValue("Server_Name")(0)
    '*** Remove leading "OpenAgent"
    urlstring = StrRight(webform.Query_String_Decoded(0),"&")

    If urlstring <> "" Then
        '*** Get all params passed to agent
        urlarr = Split(urlstring,"&")
        For i = LBound(urlarr) To UBound(urlarr)
            urlvaluename = Split(urlarr(i),"=")
            urldata(urlvaluename(0)) = urlvaluename(1)
        Next

        If IsElement(urldata("date")) = False Then
            urldata("date") = Format$(Now(),"mm/dd/yyyy")
        End If
    Else
        urldata("date") = Format$(Now(),"mm/dd/yyyy")
    End If

    '*** Get first and last date of current month
    Set startDate = New NotesDateTime(Format$(urldata("date"),"mm/01/yyyy"))
    Set endDate = New NotesDateTime(startdate.DateOnly)
    Call endDate.AdjustMonth(1)
    Call endDate.AdjustDay(-1)

    currDate = CDbl(CDat(startDate.DateOnly))
    startweekday = Weekday(Cdat(startDate.Dateonly))

    '*** HTML header
    Print "Content-type: text/html" ' & CRLF
    Print |<table class="calendar">|
    '*** Create calendar header with weekdays
    Print |<tr><td colspan=7 class="labelMonthYear">| + Format$(CDat(startDate.DateOnly),"mmmm yyyy") + |</td></tr>|
    Print |<tr class="calendarHeader">|
    Print |<td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td>|
    Print |</tr>|

    '*** Build rows for the weeks
    For i = 1 To 6
        Print |<!-- Start row | & i & | -->|
        Print |<tr class="calendarRow" id="calendarRow| & i & |">|
        For j = 1 To 7
            If j < startweekday And i = 1 Then
                Print |<td class="emptyCell"></td>|            ' Blank cell before dates
            ElseIf currDate >= CDbl(CDat(startDate.DateOnly)) And currDate <= CDbl(CDat(endDate.DateOnly)) Then
                cellclass = "calendarCell"
                If j = 1 Then
                    cellclass = cellclass + " sundayCell"
                End If
                If j = 7 Then
                    cellclass = cellclass + " saturdayCell"
                End If
                Print |<td class="| + cellclass + |" id="| + Format$(CDat(currDate),"yyyy-mm-dd") + |">|
                Print Day(CDat(currDate))    ' Day number
                Print |</td>|
                currDate = currDate + 1
            Else
                Print |<td class="emptyCell"></td>|            ' Blank cell after dates
            End If
        Next
        Print |</tr>|
        Print |<!-- End row | & i & | -->|
        Print ""
        If currDate >= CDbl(CDat(endDate.DateOnly)) Then
            Exit For
        End If
    Next
    Print |</table>|
End Sub

I am setting the id attribute on the cells to the date in yyyy-mm-dd format, and I will also use that in the categorized view that will later use. Using ISO 8601 for dates have several advantages, in our case particular because we don’t have to worry about the / character that will mess up the URL to the Domino view we will call later.
I also use class attributes on the cells, so CSS can be used to easily format the calendar.
Next we create the web page where we will insert the calendar and also display the entries for any selected day. We load jQuery from Googles CDN, and after the DOM is fully loaded by the browser, we make an ajax call to the Domino server and get the HTML of the calendar back.

After the calendar is retrieved, we use jQuery to trigger a Javascript function on click on any date cell. The code will detect the id of the cell, which just happens to be the date, and then performs another ajax call to teh Domino server, this time to the view to return all entries for the selected date. The data returned is then inserted into a div.

<!doctype html> 
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Calendar Test</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
</head>
<script>
    // The following function is executed after page is fully loaded
    $(document).ready(function () {
        var remoteURL = "http://www.texasswede.com/test/calendar.nsf/WebCalendar?OpenAgent";
        var viewURL = "http://www.texasswede.com/test/calendar.nsf/CalendarView?OpenView";
        // Load the calendar HTML from our Domino server using ajax
        $.get(remoteURL,
        function(data) {
                // Update div with id 'ajaxCalendar' with HTML calendar from server
                $("#ajaxCalendar").html(data);
                // Set all calendar cells to trigger on click
                $(".calendarCell").each( function(i) { 
                        // Get the id (i.e. selected day) of the cell clicked
                        var id = $(this).attr("id");               
                        $(this).click( function() {
                        // Call view on Domino server and return entries for selected day
                        $.get(viewURL, { RestrictToCategory: id },
                                function(data) {
                                        // Put list of entries in viewData div
                                        $("#viewData").html(data);
                                 });
                        });
                } );
        });
});
</script>
<style>
    td.calendarCell {
        border: 1px dotted black;
        height: 30px;
        width: 30px;
        text-align: center;
        vertical-align: middle;
    }
    td.emptyCell {
        background-color: #EFEFEF;
        height: 30px;
        width: 30px;
    }
    td.sundayCell {
        background-color: #DDDDDD;
        color: #DD0000;
    }
    td.saturdayCell {
        background-color: #DDDDDD;
    }
    .labelMonthYear {
        font-family: Arial;
        font-size: 12pt;
        text-align: center;
    }
  </style>
  <body>
    <div id="ajaxCalendar"></div>
    <br>
    <div id="viewData"></div>
  </body>
</html>

What’s left to do to get this all to work is to create the following Domino design elements:

  1. A form to use for entering calendar data. I called it “Calendar Entry”, and just put two fields on it, ‘CreatedDate’ (computed for display, using @Now) and ‘Title’ (text field).
  2. A view called ‘CalendarView’, with two columns. The first one is categorized and is displaying the created date in yyyy-mm-dd format, while the second one is displaying the title field and adding an HTML line break after. The view is set to treat content as HTML.
  3. A form called ‘$$ViewTemplate for CalendarView’, set to treat form as HTML. The form only contains an embedded view element, pointing to ‘CalendarView’, and it is set to return data as HTML as well.

This is the formula I used in the first column of the ‘CalendarView’ view:

y:= @Year(CreatedDate);
m:= @Month(CreatedDate);
d:= @Day(CreatedDate);
yyyy:=@Text(y);
mm:=@If(m<10;"0";"") + @Text(m);
dd:=@If(d<10;"0";"") + @Text(d);
yyyy + "-" + mm + "-" + dd

And this is what it looks like when finished:

This is just one example of how you can combine Domino (agents, views and forms) with jQuery in order to integrate Domino based data into your web applications.

Happy coding!

How to detect changes in fields on a form

Posted on November 16, 2012 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino, Programming 3 Comments

A question I have seen a few times in the developerWorks forums is how to detect what values (often names) have been added in a multi-value field.

This is not very difficult to do in Lotusscript, and there are a few different ways to do it. I prefer to use lists, but you can of course use arrays as well. The basic idea is to declare a global variable to hold the initial value of the field, populate it when the document is either opened or put into edit mode, and then checked when the document is saved.

Globals:
Dim oldValue List As String

PostModeChange:
Dim oldarray as Variant
'*** Create array, assume ; as item separator in field
oldarray = Split(uidoc.FieldGetText("myMultiValueField"),";")
'*** Build a list of values
ForAll o in oldarray 
    oldValue(o) = o 
End ForAll

QuerySave: 
Dim newarray as Variant
Dim newValue List As String
'*** Create array, assume ; as item separator in field
newarray = Split(uidoc.FieldGetText("myMultiValueField"),";")
'*** Compare with values in list
ForAll n in newarray
    '*** Check if value is not in global list, then it is new
    If IsElement(oldValue(n)) = False Then
        newValue(n) = n    ' Add new value to list
    End If
End ForAll
'*** Loop through all new values and print them
ForAll nv in newValue 
    Print nv + " is new." 
End Forall
 

The same technique can be used to detect what fields have changed since the document was opened. Just store the values of all fields (except any starting with $) in a list, then check the values in the fields against that list when saving the document.

 
Globals:
Dim oldValue List As String

QueryOpen:
'*** Build a list of values with field name as listtag
ForAll i in doc.Items 
    If Left$(i.Name,1)<>"$") Then
        oldValue(i.Name)=i.Text
    End If
End ForAll

QuerySave: 
Dim modified List As String
Dim tmpValue As String
'*** Compare current fields with values in list
ForAll o in oldValue 
    '*** Check if value is the same or not
    tmpValue = uidoc.FieldGetText(Listtag(o))   ' Get current field value
    If tmpValue <> o Then
        modified(ListTag(o))=tmpValue    ' Add new value to list of modified fields
    End If
End ForAll
'*** Loop through all modified fields and display new value
ForAll m in modified
    Print Listtag(m) + " was changed from " + oldValue(Listtag(m)) + " to " + m
End Forall
  

All very easy when you know how to do it. And again, it shows the power of lists.

Export from Notes to Excel – 3 different ways

Posted on November 14, 2012 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino, Programming 14 Comments

While reading the developerWorks forums, I have noted that some tasks seem to be common, and users often have issues with it. One very common is to export data from Notes/Domino to Excel. My guess is that some manager/executive want to get the data to manipulate and analyze it in Excel, which they know better, and where reporting can be done easier.

First of all, for anyone that want to do real integration with Excel (or Word, or any other office program), I would suggest to look at the presentations given by John Head at Lotusphere and other conferences in the past:
Lotusphere 2011 – JMP208
IamLUG 2009 – Integration and Coexistance
Lotusphere 2006 – BP309
Lotusphere 2005 – JMP108

But if you just need to export raw data to Excel, there are a couple easy ways to do that. You don’t need to automate Excel, something the programmers posting in the forums seem to frequently do. That just makes things more complicated, and if you run the code in a server agent, Microsoft Office have to be installed on the server itself. Different versions of Excel also cause different issues.

The different methods I use to export Notes data to Excel are as follows:

  • Create a CSV file, which can be opened in Excel
  • Create a HTML table in a file with .xls extension, which can be opened in Excel
  • Create a HTML table and return it through a browser, with a content type set to open in Excel.

Depending on what the requirement is, I usually choose one of those method.

 

Method 1 – CSV file (local)

The easiest way to get data from Notes to Excel (or any other spreadsheet program) is to simply save the data as  comma-separated values (CSV). Use regular Lotusscript file operations and write the values to the file, encased in double quotes and separated by a comma. You need to build a string containing a complete line, as the Print statement adds a line break to the end automatically.

A CSV file could look like this:

FirstName,LastName,Department,StartYear
"Karl-Henry","Martinsson","IT","2002"
"John","Smith","Accounting","2009"

 

The first row is the header, with the field names listed. This helps on the receiving side, but is optional. Dates and numbers don’t need quotes around them, as long as they don’t contain commas. So make a habit to format any numbers without commas.

 

Method 2 – HTML file (local)

This method is very similar to the CSV method. The difference is that you create a table in HTML, matching the cells in Excel you want to create/populate. But instead of creating a file with the extension .htm or .html, you give it the extension .xls. Excel is intelligent enough to identify it as HTML and map the content correctly.

The biggest advantages of using a HTML file instead of CSV is that you get more control over the formatting. By using colspan and rowspan, you can merge cells together, for example in a header. You can also use markup to make cells bold or italic, or even set the text and background colors.

 

Method 3 – HTML (through browser)

This method is a variant of method 2. But instead of calling the agent inside the Notes client and creating a file somewhere in the file system, the agent is called through a URL. This means the Domino HTTP task must be enabled on the server. The URL can be called from inside the Notes client using the @URLOpen function, or the OpenURL method of the NotesUIWorkspace class.

Instead of writing to a file, use the Print statement to print to the browser. The first line printed must be the content type, so the browser realize what application to open the file in. For Excel, it looks like this:

Print "content-type:application/vnd.ms-excel"

 

It also works with (among other) “application/msexcel” and “application/xls”, but the one above is the official one, so I suggest using that.

After you print the content type, simply print the HTML table code to the browser. This will open the HTML in Excel after the agent is done. It’s that easy.

 

Stack Exchange

profile for Karl-Henry Martinsson on Stack Exchange, a network of free, community-driven Q&A sites

Recent Posts

  • Domino 14 is now available
  • Domino 14 Early Access Program
  • Announced: Engage 2024
  • Integrate Node-RED with Notes and Domino
  • Notes and Domino v12 is here!

Recent Comments

  • Theo Heselmans on Announced: Engage 2024
  • Lotus Script Multi-thread Message Box [SOLVED] – Wanted Solution on ProgressBar class for Lotusscript
  • Viet Nguyen on Keep up with COVID-19 though Domino!
  • Viet Nguyen on Keep up with COVID-19 though Domino!
  • Mark Sullivan on Looking for a HP calculator? Look no further!

My Pages

  • How to write better code in Notes

Archives

  • December 2023 (1)
  • October 2023 (2)
  • September 2023 (1)
  • June 2021 (1)
  • April 2021 (2)
  • March 2021 (1)
  • August 2020 (3)
  • July 2020 (2)
  • April 2020 (2)
  • March 2020 (1)
  • December 2019 (2)
  • September 2019 (1)
  • August 2019 (2)
  • July 2019 (2)
  • June 2019 (3)
  • April 2019 (2)
  • December 2018 (1)
  • November 2018 (1)
  • October 2018 (5)
  • August 2018 (2)
  • July 2018 (3)
  • June 2018 (2)
  • May 2018 (1)
  • April 2018 (2)
  • March 2018 (1)
  • February 2018 (2)
  • January 2018 (4)
  • December 2017 (3)
  • November 2017 (2)
  • October 2017 (2)
  • September 2017 (1)
  • August 2017 (2)
  • July 2017 (6)
  • May 2017 (4)
  • February 2017 (1)
  • January 2017 (2)
  • December 2016 (2)
  • October 2016 (3)
  • September 2016 (4)
  • August 2016 (1)
  • July 2016 (2)
  • June 2016 (2)
  • May 2016 (3)
  • April 2016 (1)
  • March 2016 (4)
  • February 2016 (2)
  • January 2016 (4)
  • December 2015 (3)
  • November 2015 (2)
  • October 2015 (1)
  • September 2015 (2)
  • August 2015 (1)
  • July 2015 (5)
  • June 2015 (2)
  • April 2015 (2)
  • March 2015 (3)
  • February 2015 (2)
  • January 2015 (10)
  • December 2014 (1)
  • November 2014 (3)
  • October 2014 (3)
  • September 2014 (13)
  • August 2014 (6)
  • July 2014 (5)
  • May 2014 (3)
  • March 2014 (2)
  • January 2014 (10)
  • December 2013 (5)
  • November 2013 (2)
  • October 2013 (5)
  • September 2013 (4)
  • August 2013 (7)
  • July 2013 (3)
  • June 2013 (1)
  • May 2013 (4)
  • April 2013 (7)
  • March 2013 (8)
  • February 2013 (9)
  • January 2013 (5)
  • December 2012 (7)
  • November 2012 (13)
  • October 2012 (10)
  • September 2012 (2)
  • August 2012 (1)
  • July 2012 (1)
  • June 2012 (3)
  • May 2012 (11)
  • April 2012 (3)
  • March 2012 (2)
  • February 2012 (5)
  • January 2012 (14)
  • December 2011 (4)
  • November 2011 (7)
  • October 2011 (8)
  • August 2011 (4)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (4)
  • April 2011 (4)
  • March 2011 (7)
  • February 2011 (5)
  • January 2011 (17)
  • December 2010 (9)
  • November 2010 (21)
  • October 2010 (4)
  • September 2010 (2)
  • July 2010 (3)
  • June 2010 (2)
  • May 2010 (3)
  • April 2010 (8)
  • March 2010 (3)
  • January 2010 (5)
  • November 2009 (4)
  • October 2009 (7)
  • September 2009 (1)
  • August 2009 (7)
  • July 2009 (1)
  • June 2009 (4)
  • May 2009 (1)
  • April 2009 (1)
  • February 2009 (1)
  • January 2009 (3)
  • December 2008 (1)
  • November 2008 (1)
  • October 2008 (7)
  • September 2008 (7)
  • August 2008 (6)
  • July 2008 (5)
  • June 2008 (2)
  • May 2008 (5)
  • April 2008 (4)
  • March 2008 (11)
  • February 2008 (10)
  • January 2008 (8)

Categories

  • AppDev (10)
  • Blogging (11)
    • WordPress (5)
  • Design (5)
    • Graphics (1)
    • UI/UX (2)
  • Featured (5)
  • Financial (2)
  • Food (5)
    • Baking (3)
    • Cooking (3)
  • Generic (11)
  • History (5)
  • Hobbies (10)
    • LEGO (4)
    • Photography (4)
  • Humor (1)
  • IBM/Lotus (178)
    • #Domino2025 (14)
    • #DominoForever (8)
    • #IBMChampion (46)
    • Administration (7)
    • Cloud (7)
    • CollabSphere (9)
    • Community (49)
    • Connect (33)
    • ConnectED (12)
    • Connections (3)
    • HCL (15)
    • HCL Master (1)
    • IBM Think (1)
    • Lotusphere (46)
    • MWLUG (25)
    • Notes/Domino (99)
      • Domino 11 (7)
    • Sametime (8)
    • Verse (14)
    • Volt (3)
    • Watson (6)
  • Life (8)
  • Microsoft (7)
    • .NET (2)
    • C# (1)
    • Visual Studio (1)
  • Movies (3)
  • Old Blog Post (259)
  • Personal (23)
  • Programming (84)
    • App Modernization (11)
    • Formula (4)
    • Lotusscript (47)
    • NetSuite (4)
      • SuiteScript (3)
    • node.js (4)
    • XPages (4)
  • Reviews (9)
  • Sci-Fi (4)
  • Software (24)
    • Flight Simulator (2)
    • Games (4)
    • Open Source (2)
    • Utilities (6)
  • Technology (37)
    • Aviation (3)
    • Calculators (2)
    • Computers (6)
    • Gadgets (7)
    • Mobile Phones (7)
    • Science (3)
    • Tablets (2)
  • Travel (7)
    • Europe (1)
    • Texas (2)
    • United States (1)
  • Uncategorized (16)
  • Web Development (50)
    • Frameworks (23)
      • Bootstrap (14)
    • HTML/CSS (12)
    • Javascript (32)
      • jQuery (23)
  • Prev
  • 1
  • …
  • 15
  • 16
  • 17
  • 18
  • Next

Administration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Tracking

Creeper
MediaCreeper
  • Family Pictures
© TexasSwede 2008-2014