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

Category Archives: Programming

Connect 2014 – More about the sessions

Posted on January 22, 2014 by Karl-Henry Martinsson Posted in Connect, IBM/Lotus, Lotusphere, XPages Leave a comment

The sessions at Lotusphere/Connect are focusing more and more on XPages each year. I don’t think there are really any sessions about classic Notes development this year. Currently I am not able to use XPages at work, due to the client environment we run (Lotus Notes 8.5.2 Basic in Citrix), but the sessions are still great (see video below) and I am learning new things every year. Hopefully we will soon switch the client to IBM Notes 9.0 so I can use all this knowledge to build some really cool and useful applikations for our users.

[embedyt]http://youtu.be/0ViUTfAzoTo[/embedyt]

I am also going to some admin-related sessions, this is an area I am trying to get more knowledgeable in, after our network/Domino administrator left in 2012.

A frequently comparison is that going to Lotusphere is like trying to drink from a fire hose. There is so much info that you can’t take it all in. You will soak up a lot of good and useful information, and if there are things you don’t understand, you can ask the speakers after the sessions, or even later in the week, as you surely will see them around in the hallways, at other sessions. You can also ask questions to the Best Practices speaker at Gurupaloza (Thursday 10am) and the IBM developers at Ask the Developers (Thursday 1.30pm) sessions. The latter is often tongue-in-cheek called Beat the Developers. If you have less technical questions, for example about the future direction of a product or if a particular feature is planned for a future release, don’t miss the Ask the Product Managers (Thursday 11.15am).

Talking about those sessions, here is a friendly reminder: keep the right questions in the right sessions. Every year there is someone who asks questions about future directions of products at Gurupaloza or asks about a particular problem/function in the Product manager session. Doing this irritates the rest of the audience, and causes someone else not to get the time to ask his/her question. Also, if you have a very specific technical question, don’t bring that to these sessions, go see the developers in the lab instead during the week. Nobody is interested in the printing problem one user at your office is having with one specific type of printer… That is a support question.

The most important rule however, is one question per user. If you have two questions, go to the back of the line and wait for your turn. Don’t try to hog the microphone.

Code – Mask text to remove PII

Posted on December 2, 2013 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino 4 Comments

Sometimes you need to remove personal identifiable information (PII) from the data you present in an application or on a web page. In the last couple of weeks this issue popped up twice, including one application which needs to be be HIPAA compliant. One solution is to mask any personal identifiable data so that the recipient can still verify the information, without sending it all in clear. I am sure you all seen this on for example credit card statements, with only the last 4 digits of your credit card number displayed.

I wrote a simple  Lotusscript function to do this, and I thought I would share it so others can use it as well. You pass a string to mask, the number of characters to leave un-masked and where the unmasked characters should be displayed (“B” for beginning or “E” for end).

MsgBox masktext("TexasSwede",3,"B")

This line would display Tex*******

MsgBox maskText("1234567890",4,"E")

This line would display ******7890

Enjoy!

 

%REM
    Function maskText
    Description: Masks a text with asterisks, leaving the num first or
    last characters visible. Direction is "B" (beginning) or "E" (end).
    Created by Karl-Henry Martinsson - texasswede@gmail.com 
%END REM
Function maskText(value As String, num As Integer, direction As string) As String
    Dim tmp As String
    Dim i As Integer
    If Len(value)>num Then
        If Left$(UCase(direction),1)="B" Then    ' Start at the beginning
            tmp = Left$(value,num)
            For i = num+1 To Len(value)
                tmp = tmp + "*"
            Next
        Else                                     ' Start at the end
            tmp = Right$(value,num)
            For i = Len(value) To num+1 Step -1
                tmp = "*" + tmp
            Next
        End If
    Else
        tmp = value
    End If
    maskText = tmp
End Function

API for ZIP Code Distance, Radius, and more

Posted on October 16, 2013 by Karl-Henry Martinsson Posted in Programming, Web Development 2 Comments

 

The other day I stumbled on a really cool website, where they offer a free API to calculate distance between two US ZIP codes, all ZIP codes in a specific radius from a given ZIP code, as well as a few other ZIP code related functions.

http://zipcodedistanceapi.redline13.com/

http://zipcodedistanceapi.redline13.com/

The results can be returned in different formats, like JSON, XML and (in some cases) CSV. Highly recommended! The URL is http://zipcodedistanceapi.redline13.com/

I am considering creating a Lotusscript class for some of these functions, so stay tuned!

 

25 years in the IT industry

Posted on September 19, 2013 by Karl-Henry Martinsson Posted in Personal, Programming, Software, Technology 2 Comments

Today it is exactly 25 years since I started my first real job in the IT industry. On September 19, 1988 I started working at Microsoft in Sweden as employee #42, right out of 12th grade of school. So how did I end up working at Microsoft at age 19? Well, I had a bit of bad luck, which turned into good luck. Let me explain. :-)

I started programming in 7th grade. In the late fall of 1982, a computer club was founded in my school. When we came back to school after Christmas break, in January 1983, some older students taught some classes in BASIC in the evenings. Attending those classes were a requisite for getting the magnetic card that gave us access to the computer room (as long as there were no regular classes taking place there). In preparation of the classes starting, I went to the library and picked up a book on programming the ABC 80 computers we had in school. I started learning programming by writing code by hand in a notebook, to understand the concept. I spent the Christmas break learning BASIC, so when the classes started in January, I had a pretty good understanding of the concept of programming. A couple of years later we got another type of computer in school, and I switched to Pascal as the programming language of choice. I spent on average 3 or 4 hours in the computer room each day (during lunch breaks and after school) for the next 5 1/2 years… I even managed to convince the school to let me borrow one of the computers and take it home during one Christmas break, as I was working on a big project.

Hersby skola on Lidingö, where I spent the years 1982-1988 learning programming.

Hersby skola on Lidingö, where I spent the years 1982-1988 learning programming.

My schedule in the last year of High School (1987-88). Computer Science is coded “Da”, and we had it Tuesday and Friday.

After finishing what’s in Sweden is called gymnasium (equivalent of High School in the US), I was not motivated to spend additional 4 years or more going to university. However, I found a one-year specialty course in Systems Programming and Computer Science, where they crammed 2+ years into one year, with 8-hour days five days/week. I applied and was accepted. However,after a couple of weeks, the assistant principal (who was also one of our main teachers) came in and told us that the class had to be cancelled. The class was simply too small, and they had not been able to get any more students to apply. The class was postponed and would start over in January 1989.

In the mean time we were encouraged to find an internship or entry-level job in the IT industry. I picked up the yellow pages section of the phone book and looked up computer companies. Being a person thinking outside the box, I started going through the companies in reverse order. I figured that anyone else in the class would start from the beginning. I started cold-calling some companies, and after a few calls, I got a hit. This company called Microsoft was interested, they needed someone in tech support, to answer calls from customers and solve their problems.

I had not really heard much about Microsoft at this time. We used CP/M-86 as the operating system in school, and I had only seen Windows 1.0 once or twice, and never really used it. I knew about PCs, but I mostly associated them with IBM. I sent the then-manager of the support department, Arne Josefsberg, my grades from school (I did not have a resume yet). Later I found out he actually never even looked at my grades…
I called Arne back the following week to verify that he got the letter, and he asked me to come in for an interview the next day, Friday September 16. I took the subway to the Microsoft office and met with Arne, who performed a short interview and a little test of my problem solving skills. He had me perform some actions in Word for DOS, a for me then totally unknown program, to see how quickly I could solve some problems. A few minutes later I walked out the door with a job waiting for me the following Monday and the user’s manual to Windows 2.03 under my arm with orders to read it over the weekend… So on September 19, 1988 I started working at Microsoft, my first real job in the computer industry, or IT business as it is called these days.

I have to say that I did learn an enormous amount of things at Microsoft. There was no formal training, you were expected to learn things on your own. But my coworkers went out of their way to teach me things. Thanks Anna, Micael, Magnus, Rolf and everyone else that helped me and taught me about the Microsoft products. After working at Microsoft during the fall I went back to school and finished the education, while working at Microsoft during school holidays and the summer, as well as for a few months after graduation.

I then served in the Swedish Air Force for 11 months, as the country still had mandatory military service at this time. I actually intended to go back to Microsoft after the Air Force, but I was offered a job as a programmer right before I left the service, and I started my career as a programmer/developer in early 1991. It was now I started playing with Visual Basic 1.0, released in the summer of 1991. I learned programming using traditional BASIC back in 1982-83, before switching to Pascal some time around 1985, and then to C in 1989. I quickly realized that Visual Basic was a great product. It removed much of the complexity of creating Windows programs, and the developer could focus on the actual functionality and business logic instead of having to write pages of code to handle windows and events.

After the company I worked for went bankrupt in the end of 1992, I got a job at IDG Sweden as a journalist at the weekly publication Computer Sweden. It was during my time  there I learned about (among other things) HTML and Lotus Notes, knowledge I still use to this day. I worked at Computer Sweden for five years, covering the PC marketplace (both hardware and software), before moving to Boston and taking a position as Notes developer with IDG in the US.

After a little over four years in Boston, my then-wife wanted to move closer to her family in Texas, so we moved to Arlington, TX and I got a job with Deep South, a Dallas-based insurance company where I still work 11 years later, as a Notes/Domino developer. I am also taking on some administration tasks, after out previous network admin and operations manager left the company last year.

I count myself very lucky to have a job I love. How many people can say that they been working 25 years with something they like? I also had the luck to work almost exclusively at good companies, and having good managers/bosses. I have for example been able to go to Lotusphere every year since 1997 (as well as a technical conference in 1996 that were a pre-cursor to Lotusphere Europe).

Finally I once more want to thank everyone who over the years helped or supported me, and who made it possible for me to be where I am today.

Class for Domino Directory lookups

Posted on September 4, 2013 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino 1 Comment

In many of my Notes programs, I need to perform lookups into the Domino Directory (the database formerly known as Name and Address Book or NAB). So my solution was to create a class that handle those lookups for me, and exposes the most common lookups as separate methods.
We have a slightly modified version of names.nsf, with a few added fields. One of them is what we call ParallelID, which is the user’s ID in a system called (surprise!) Parallel. Since I perform that lookup all the time, I created a separate method for that one called GetParallelID(). Same with manager lookup for a user, I created GetManagerName() for that.
The methods you probably will use the most are GetText() and GetValue().

Since I think this class could come in handy for others, here it is. Enjoy!

Option Public
Option Declare

Class NotesAddressBook
  Private NABdb As NotesDatabase
  Private server As String
  Private nabname As String
  Public silent As Boolean

  Public Sub New(servername As String)
    me.silent = false
    Call LoadNABdb(servername)    
  End Sub

  Public Function GetNABdoc(personname As String) As NotesDocument
    Dim NABview As NotesView
    If NABdb Is Nothing Then
      Call LoadNABdb("")        
    End If
    If Not NABdb Is Nothing Then
      Set NABview = NABdb.GetView("PeopleByFirstname")
      Set GetNABdoc = NABview.GetDocumentByKey(ShortUserName(personname))
    Else
      Set GetNABdoc = Nothing
    End If
  End Function

  Public Function database() As NotesDatabase
    If NABdb Is Nothing Then
      Call LoadNABdb("")        
    End If
    If Not NABdb Is Nothing Then
      Set database = NABdb
    End If
  End Function

  Public Function GetValue(personname As String, fieldname As String) As Variant
    Dim NABdoc As NotesDocument
    Set NABdoc = GetNABdoc(personname)
    If NABdoc Is Nothing Then
      If me.silent = False then
        Msgbox "No document found for '" & personname & "' in " & nabname & " on " & server & ".",,"NotesAddressBook::GetNABdoc()"
      End If
      GetValue = ""
    Else
      GetValue = NABdoc.GetItemValue(fieldname)
    End If
  End Function

  Public Function GetText(personname As String, fieldname As String) As String
    Dim tmp As Variant
    tmp = GetValue(personname, fieldname)
    If IsArray(tmp) Then
      GetText = CStr(tmp(0))
    Else
      GetText = CStr(tmp)
    End If  
  End Function

  Public Function GetName(personname As String, fieldname As String) As NotesName
    Dim tmpValue As String
    tmpValue = GetText(personname, fieldname)
    If tmpValue <> "" Then
      Set GetName = New NotesName(tmpValue)
    End If
  End Function

  Public Function GetNameByParallelID(parallelid As String) As String
    Dim view As NotesView
    Dim doc As NotesDocument 
    Dim tmpValue As String
    Set view = NABdb.GetView("(LookupUserID)")
    Set doc = view.GetDocumentByKey(parallelid)
    If doc Is Nothing Then
      Exit Function
    End If
    tmpValue = doc.GetItemValue("FirstName")(0) & " " 
    If doc.GetItemValue("MiddleInitial")(0)<>"" Then
      tmpValue = tmpValue & doc.GetItemValue("MiddleInitial")(0) & " "
    End If
    tmpValue = tmpValue & doc.GetItemValue("LastName")(0)
    If tmpValue <> "" Then
      GetNameByParallelID = tmpValue
    End If
  End Function  

  Public Function GetCommonName(personname As String, fieldname As String) As String
    Dim tmpName As NotesName
    Set tmpName = GetName(personname, fieldname)
    If Not tmpName Is Nothing Then
      GetCommonName = tmpName.Common
    End If
  End Function

  Public Function GetManagerName(personname As String) As String
    GetManagerName = GetCommonName(personname, "Manager")
  End Function

  Public Function GetParallelID(personname As String) As String
    GetParallelID = GetText(personname, "ParallelID")
  End Function

  Public Function GetBranch(personname As String) As String
    GetBranch = GetText(personname, "Location")
  End Function

  Private Sub LoadNABdb(servername As String)
    Dim session As New NotesSession
    '*** Some users have a local replica of Domino Directory
    '*** but it would never be used unless the code is running
    '*** in a local database, otherwise current server is used. 
    If servername = "" Then
      servername = session.CurrentDatabase.Server
      If servername = "" Then  
        '*** Code running in local database/replica
        server = "Local"
        nabname = "dsnames.nsf"  
      Else
        server = servername
        nabname = "names.nsf"        
      End If
    Else
      server = servername
      nabname = "names.nsf"
    End If
    Set NABdb = session.GetDatabase(servername, nabname)
    If NABdb Is Nothing Then
      Msgbox "Failed to open " & nabname & " on " & server & ".",,"GlobalConfig::New()"
    End If
  End Sub

  Private Function ShortUserName(longname As String) As String
    Dim namearray As Variant

    '*** Remove any periods in name, some users have that
    longname = Replace(longname,".","")

    namearray = Split(longname," ")
    '*** Check if there is middle inital or 3 parts to the name 
    If UBound(namearray) >=2 Then
      '*** check if middle name/initial is just one char (initial)
      If Len(namearray(1))=1 Then
        namearray(1) = ""  ' Remove value
      End If     
    End If
    '*** Join name parts together again and return to calling function
    ShortUserName = FullTrim(Join(namearray))
  End Function

End Class

Some personal thoughts and a big Thank You

Posted on September 2, 2013 by Karl-Henry Martinsson Posted in Generic, Lotusphere, Personal, Programming 6 Comments

Last week, Volker wrote this excellent article about Tomas Duff (a.k.a. Duffbert). Then yesterday the news reached me about the sudden death of Rob Wunderlich, a long-time member of the Lotus community. I had already started on a post — in preparation of my upcoming 25 year anniversary of becoming an IT professional — where I was going to acknowledge a number of people who meant much to me and who were important in making me to what I am today. I have decided to post this text a bit earlier than originally planned.

There are so many people who helped me and supported me over the years, and without them I would not be where I am now professionally. Some took a chance on me and gave me jobs where I grew professionally, others were more like mentors or inspirations, and some were teaching me how to do things with computers or in code. I know I am probably forgetting many who deserve to be mentioned. But I want to thank the following:

  • Tonny Olsson – my cousin who worked at Hewlett-Packard and let me see my first computer (complete with a plotter and an acoustic modem he used to connect to HP from our house) in or around 1975. He also introduced me to the world of HP calculators and RPN.
  • Peter Nilsson – my childhood friend and classmate, who introduced me to Basic programming when he got a VIC-20. We spent an evening (right after he got it) entering a program from the handbook, but we did not get it to work that day. Later on we got some programs working.
  • Henry Jacobsson – My teacher in computer science/programming in High School, who allowed me write my code in Turbo Pascal for CP/M-86 instead of the special language COMAL (a mix between BASIC and Pascal). He also taught me the basics of how to plan/design an application. I also want to thank Henry for not kicking me out when I hacked his systems administrator account and assigned myself 1MB of storage on the 30MB hard disk we had on the server. Normally each student got 4kB, but I wanted more. :-)
  • I also want to thank several of the older students in the school’s computer club, who helped us younger students when we had questions. I want to mention Hjalmar Brismar, Petter Aaro and Matthias Bolliger, who were always there with advise and knowledge.
  • Arne Josefsberg – head of tech support at Microsoft, he took a chance and gave me a job without me having touched any Microsoft program previously.
  • Rolf Åberg, Magnus Andersson, Anna Söderblom and Micael Dahlquist – also at Microsoft. They helped me learn all kind of new things, from Windows programming using C and the Windows SDK to regular C programming using QuickC, from Excel to Word for DOS. I also ended up wothing with Micael at another job a few years later.
  • Per Engback and Ingvar Gratte – my two main teachers at the systems programming class. Despite this being just a one-year class, I learned plenty, especially C programming and Unix.
  • Krister Hanson-Renaud and Harald Fragner – two programmers/hackers who inspired me over the years, and who also introduced me to the world of Bulletin Board Systems (BBS). I had been exploring some earlier bulletin board systems back in 1987-88, but it was in 1989-90 I became “social” on these networks. Both Harald and Krister wrote their own BBS systems, and I ended up running one of them myself for a short time, but it was more of a test.
  • All my friends on CT and SKOM, the two BBS:s I frequented the most, between 1990 and some time in 2004. Here I learned about online debates, flame wars and of course plenty about hardware, software and programming techniques.
  • Lars Dahmén – the editor-in-chief at Computer Sweden who hired a 22 year old programmer/hacker in the role of journalist, despite no previous journalistic experience. Obviously he saw some possibilities in me, as I stayed for five years until I moved to IDG in Boston. Lars was a great boss, a very competent manager and is a very nice person. It’s hard to find that combination, and I think I have to say that he is the best manager I ever had. Thank you for not giving me too much grief about my messy desk and my shot-up hard disk on my bookshelf. He also tasked me with developing some of my first actual Notes applications, for internal use at the magazine, and approved of my moonlighting with Notes development (see Enrico Barile below)
  • Eva Sparr – the managing editor at Computer Sweden, and who I reported to directly. She usually gave me very free reign to explore new stories and test software/hardware as I saw fit, something that helped me develop my analytical skills.
  • Erik Geijer, Anders Lotsson, Maria Lindström and Kenneth Bäcklund – four of my colleagues at the magazine, experienced journalists who gave me a crash-course in writing, journalism and penmanship. A big thank you for all the time you spent giving me advise and proof-reading my articles. Erik also introduced me to HTML in 1994.
  • Enrico Barile – he exposed me to Lotus Notes, and started me on the path to where I am now. We spent many evenings at his office, building websites using InterNotes Web Publishing, which eventually merged with the Notes server in version 4.5 and became what we today know as the Domino server. I mainly worked on the HTML part, but I did learn a lot about Notes/Domino.
  • Morris Effron – my boss at IDG in Boston. He hired me from across the Atlantic, to become a full-time Lotus Notes developer. Not only did he trust in my skills and ability to learn new things (I had been writing several Notes applications, but nothing extremely complex), he sent me to several classes to increase my skills both on the technical side and on the social side. When someone from Boston, born in New York, think you are too direct and rude to the users and send you to a class to be nicer to people, that is a sign you are a bit rough around the edges. ;-)
  • And of course all my friends in the Lotus/ICS community. Over the years I have gained enormous amount of knowledge from your sessions at Lotusphere, blog entries and direct discussions (in person at conferences or through Sametime/email), or though services to the community. In addition to Tom Duff, who I already mentioned, I would like to list just a few: Rocky Oliver, Andrew Pollack, Brian Benz, Scott Good, Julian Robichaux, Francie Tanner, Rob Novak, Chris Blatnick, Declan Lynch, Chris Miller (the one-slide-man!), Paul Mooney, Bill Buchan, Mark Myers, Matt White, Bruce Elgort, Yancy Lent (thanks for PlanetLotus!), Jake Howlett (who I never met, but who’s site codestore.net have been a great resource over the years), Joe Litton, Stephan Wissel, Tim Tripcony, Nathan Freeman, and so many more. Not to forget all the Lotus/IBM people I met at Lotusphere, like Maureen Leland, Dan O’Conner, Mary Beth Raven, Susan Bulloch and all the others I been harassing over the years in the Ask the Developers lab at Lotusphere. I also want to thank everyone who presented at Lotusphere and shared their knowledge over the years.
  • Finally I would like to mention my parents, Marie-Luise and Stig Martinsson. Today (September 2) would have been my dad’s 87th birthday. They were great parents, and gave me the freedom I needed to read books all summer long (even if my mom sometimes thought I should go outside for a bit) and to take apart old radios or mechanical calculators, or solder together some electronic contraption in the basement of our house. Later, when I spent all my free time after school in the computer room, they were concerned that I was negligent with my home work, but they never forced me to abandon programming. And when I look back, I realize that all those thousands of hours spent in the computer room is what made me to what I am today.

So again, to everyone who in one way or another had a hand in bringing me to where I am today, a huge thank you. And forgive me if I did not list everyone, or I would be writing this list until Christmas…

Part of the Lotus community/bloggers meeting for BALD at Lotusphere 2011.

Part of the Lotus community/bloggers meeting for BALD at Lotusphere 2011.

 

The traditional end-of-Lotusphere picture, from Lotusphere 2010.

The traditional end-of-Lotusphere picture with part of the community, this one from Lotusphere 2010.

 

Blogger community at Lotusphere/Connect 2013. Photo by John Roling (CC-BY-NC-ND).

Blogger community at Lotusphere/Connect 2013. Photo by John Roling (CC-BY-NC-ND).

My IBM Notes project on GitHub

Posted on August 28, 2013 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino, Programming Leave a comment

github_small

I decided to play around a little, and as an experiment put up one of my Notes projects on the open source repository GitHub. You can see the result here: http://github.com/TexasSwede/Class.MailMerge

This is a script library in Lotusscript to create documents based on a source document and a template document. I have blogged about it before, but I added some functionality to it, and thought it would be easier for people to download a complete database.

 

jQuery – An Overview

Posted on July 19, 2013 by Karl-Henry Martinsson Posted in Frameworks, Javascript, jQuery, Notes/Domino, Programming, Web Development 1 Comment

Yesterday my boss asked me about a simple overview/tutorial explaining jQuery, Bootstrap and some other web technologies, and how they work together. I decided to also post the result on my blog, so here is the first part. You may recognize some code from a previous blog entry.

jQuery is a currently very popular Javascript framework/library. There are other ones, like Dojo (used by IBM in XPages) and YUI (originally developed by Yahoo), but jQuery is right now at the top when it comes to usage.
jQuery contains the plumbing behind the scene, it contains functions to let the different elements on the page talk to each other and interact, for example trigger events on click or change. It also have functions to hide and show elements (either directly or fade in or out).

One of the big benefits with jQuery is that many functions are much easier to do than in traditional Javascript. It also addresses browser inconsistency, so you don’t have to write different code for Firefox and Internet Explorer. jQuery is Javascript, just packaged in a nice library and simplified. There are also UI components and mobile components, found in jQuery UI and jQuery Mobile. Here are a couple of examples, comparing plain Javascript with jQuery: http://blog.jbstrickler.com/2010/06/vanilla-javascript-vs-jquery/.

jQuery ties into the DOM (Document Object model) of the browser/webpage in a very easy-to-use way. The way elements are addressed is identical to how you do it in CSS, using . (dot) for classes and # for individual elements.

It is not hard to start with jQuery. You do not even have to host the library on your own server, several companies (including Microsoft and Google) host jQuery (as well as other libraries and frameworks) in what is called a CDN (Content Delivery Network). You simply include a line of code in the head section of your HTML, telling the browser to load jQuery from a specified location, and you are all set:

<head>
    <title>Hello, jQuery</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
</head>

Notice that you don’t use http: or https: at the start of the URL. This is a trick that makes it work both on a http or a https site. However, if you have the code locally in the file system on your computer (like many do before uploading the html file to a server), you must add http: at the beginning for it to load.

Let take a look at our first jQuery example. Below we have a very simple piece of HTML code:

<body>
    <button id="btnSave">Save</button>
    <div id="messageBox"></div>
</body>

What we want to do is that when the button is clicked, a message should be displayed in the div with ID messageBox. That is done with the following piece of jQuery:

$("#btnSave").click( function() { 
    $("#messageBox").html("You clicked the Save button."); 
});

What this do is to replace everything inside the div with the text/HTML code we specify. The second line is the code to execute when the event specified triggers/fires. You can put triggers on almost any element, and depending on the element type, you have different triggers.

The code between the first and last curly brackets { } is being executed when the event is triggered. As you can see, I have the code I showed earlier nested inside this code. What all this does is to wait until the page is loaded, then start creating event triggers.

There are two schools when it comes to where you put the jQuery code. Soem developers prefer to put the code inside <script> tags at the end of the page, after all HTML code and right before </body>. That is is so that the code is not executed until the page (and all the elements on it) have been loaded.

There is another way to do it, as well. This one allows you to put the code in the <script> section of the header section, but it us using jQuery to not load any code until the page has finished loading:

$(document).ready(function () {
    // Setup the element with id "btnSave" to react on click
    $("#btnSave").click( function() {
        // When clicked, set the innerHTML of the element with
        // id "messageBox" to the specified html string.
        $("#messageBox").html("You clicked the Save button.");
    });
});

The important thing is that you can not start put events on elements until they have been created on the page, or nothing will work.

One of the really cool features with jQuery is how easy it is to call another page/url and get something back. This is commonly called Ajax (Asynchronous Javascript and XML), even if it these days more often than not involves getting JSON back instead of XML.
JSON stands for Javascript Object Notation and is a way to package data in the same way you would do if you created a Javascript object. A simple example would look like this:

{
    "FirstName":"Karl-Henry",
    "LastName":"Martinsson",
    "Department:"IT"
}

I can now assign the object to a variable (let’s call it employee) and I can then access the values using regular Javascript:

alert(employee.FirstName + " " + employee.LastName + " works in " + employee.Department);

This ease of parsing makes JSON ideal to use to retrieve values from a data source and display them on a webpage, using Javascript.

Let’s look at a more complicated example. I will call a URL on a server, which will trigger an agent to run to retrieve data from a database and return it in HTML format. This particular URL points to a Domino agent written in Lotusscript, but it could be written in any language supported by the server, like php. For a Domino server, you could also use an XPages agent.

Here is the Javascript code to call a URL and put the content returned into a element on the web page:

function loadProgressNotes(clientunid) {
    $.ajax({
        url: "/mydatabase.nsf/GetProgressNotes?OpenAgent",
        data: {"ClientUNID":clientunid,"Start":"1","Count":"10"},
        cache: false
    }).done(function(returndata) {
        $("#progressNotes").html(returndata);
    });
}

I broke this code out as a separate function, as I need/want to call it in several places. The function just contains one single jQuery function call, .ajax(). I pass a Javascript object to the function, containing the data needed by the function. Many jQuery functions works like this, you pass a Javascript object with arguments instead of passing a large number of individual arguments. You can do the same in Lotusscript, by passing an object or a custom data type to a function instead of numerous arguments.

In this particular case, I am calling .ajax() with 3 arguments. The first one is the URL to go to, the second one is the data to send to that URL, and the last one is a flag telling jQuery to add a cache buster to the end of the URL it constructs. If I would not add that, and I had recently made the same call, I would get old data, as web servers and browsers cache data for performance reasons.
The interesting thing in the code above is perhaps that the data I pass to the URL are itself a Javascript object, so we have a Javascript object where one of the elements is another object.

So what happens is that jQuery performs a call to www.domain.com/mydatabase.nsf/GetProgressNotes?OpenAgent&ClientUNID=something&Start=1&Count=10&_15614312653

The last number is the cache buster, simply a timestamp (milliseconds since midnight, Jan 1, 1970).
The program/agent on the server reads the arguments, performs whatever database lookup it needs, and generates HTML based on that. This HTML is returned by the .ajax() call in data above. The jQuery call is sitting in the background and waiting for the agent to return the data. When this is done, the .done() event is triggered.
In that event, I have written some jQuery code to update the contents of the element called “progressNotes” with whatever the AJAX call returns, in this case some HTML.

It may be more common to have the agent return JSON and parse it, putting different values into different elements on the page. Here is an example, where I go through all the input fields and text area fields on a HTML form and collect the field values/contents for any of the fields having the custom attribute called notesfield. The value of the attribute is the field name in the Domino database, making it very easy to send the data to the correct place on the server.  A typical input field could look like this:

<input notesfield="FirstName" type="text" value="" placeholder="First Name">

Below is the Javascript code, using jQuery to update the record in the Domino database and return JSON that will indicate success or failure, as well as a custom message that will either explain the reason for failure or a message that the document was updated.

var json = new Object();

myjson["ClientUNID"] = "E7A2D820EE10123C86257BAD0056A5F4";

$('input[notesfield]').each(function() {
    fieldname = $(this).attr("notesfield");
    fieldvalue = $(this).val();
    myjson[fieldname] = fieldvalue;
});

$('textarea[notesfield]').each(function() {
    fieldname = $(this).attr("notesfield");
    fieldvalue = $(this).val();
    myjson[fieldname] = fieldvalue;
});

$.ajax({
    url: "/mydatabase.nsf/UpdateClient?OpenAgent", 
    data: myjson,
    cache: false
}).done(function(returndata) {
    if (returndata.status=="Error") {
        $(".errorMessageClient").html("Error! " + returndata.msg).show();
    } else if (returndata.status=="Success") {
        $(".successMessageClient").html("Success! " + returndata.msg).show();
    });
});

As you can see, it is easy to retrieve values from the JSON you get back.

That’s all for now. Next time I will talk about Bootstrap.

Export Notes view to Excel – with multi-value fields

Posted on April 5, 2013 by Karl-Henry Martinsson Posted in Lotusscript, Notes/Domino, Programming 36 Comments

A few days ago, a question was asked on StackOverflow about how to export the content of a Notes view to Excel. The caveat was that some columns contained multiple values, but not on all documents.

To solve this, I wrote a Lotusscript class that will export view data as either CSV or as an HTML table, both can then be saved to a file and opened in Excel. I am posting the code below. Enjoy!

 

%REM
    Agent View Export
    Created Mar 27, 2013 by Karl-Henry Martinsson
    Description: Code to export a specified view as CSV.
    Copyright (c) 2013 by Karl-Henry Martinsson
    This code is distributed under the terms of 
    the Apache Licence Version 2. 
    See http://www.apache.org/licenses/LICENSE-2.0.txt
%END REM

Option Public
Option Declare

Class RowData
    Public column List As String

    Public Sub New()
    End Sub

    Public Sub SetColumnHeader(view As NotesView)
        Dim viewcolumn As NotesViewColumn
        Dim cnt As Integer
        ForAll vc In view.Columns
            Set viewcolumn = vc
            column(CStr(cnt)) = viewcolumn.Title 
            cnt = cnt + 1
        End Forall  
    End Sub

    Public Sub SetColumnValues(values As Variant)
        Dim cnt As Integer
        Dim tmp As String 
        ForAll v In values
            If IsArray(v) Then
                ForAll c In v
                    tmp = tmp + c + Chr$(13)
                End ForAll
                column(CStr(cnt)) = Left$(tmp,Len(tmp)-1)
            Else
                column(CStr(cnt)) = v 
            End If
            cnt = cnt + 1
        End ForAll          
    End Sub
End Class

Class CSVData
    Private row List As RowData
    Private rowcnt As Long

    %REM
        Function New
        Description: Open the view and read view data 
        into a list of RowData objects.
    %END REM    
    Public Sub New(server As String, database As String, viewname As String)
        Dim db As NotesDatabase
        Dim view As NotesView
        Dim col As NotesViewEntryCollection
        Dim entry As NotesViewEntry
        Dim colcnt As Integer

        Set db = New NotesDatabase(server, database)
        If db Is Nothing Then
            MsgBox "Could not open " + database + " on " + server,16,"Error" 
            Exit Sub
        End If
        Set view = db.GetView(viewname)
        If view Is Nothing Then
            MsgBox "Could not access view " + viewname + ".",16,"Error" 
            Exit Sub
        End If
        Set col = view.AllEntries()
        rowcnt = 0
        Set entry = col.GetFirstEntry()
        Set row("Header") = New RowData()
        Call row("Header").SetColumnHeader(view)
        Do Until entry Is Nothing
            rowcnt = rowcnt + 1
            Set row(CStr(rowcnt)) = New RowData()
            Call row(CStr(rowcnt)).SetColumnValues(entry.ColumnValues)
            Set entry = col.GetNextEntry(entry) 
        Loop
    End Sub

    %REM
        Function CSVArray
        Description: Returns a string array of CSV data by row
    %END REM
    Public Function CSVArray() As Variant
        Dim rowarray() As String 
        Dim textrow As String
        Dim cnt As Long
        ReDim rowarray(rowcnt) As String

        ForAll r In row
            textrow = ""
            ForAll h In r.column 
                textrow = textrow + |"| + Replace(h,Chr$(13),"\n") + |",|
            End ForAll
            rowarray(cnt) = Left$(textrow,Len(textrow)-1)
            cnt = cnt + 1
        End ForAll  
        CSVArray = rowarray
    End Function

    %REM
        Function HTMLArray
        Description: Returns a string array of HTML data by row
    %END REM
Public Function HTMLArray() As Variant
        Dim rowarray() As String 
        Dim textrow As String
        Dim cnt As Long
        ReDim rowarray(rowcnt) As String

        ForAll r In row
            textrow = ""
            ForAll h In r.column 
                textrow = textrow + |<td>| + Replace(h,Chr$(13),"<br>") + |</td>|
            End ForAll
            rowarray(cnt) = "<tr>" + textrow + "</tr>"
            cnt = cnt + 1
        End ForAll  
        HTMLArray = rowarray
    End Function

End Class

Here is an example of how to use the class:

Sub Initialize
    Dim csv As CSVData
    Dim outfile As String

    Set csv = New CSVData("DominoServer/YourDomain", "names.nsf", "People\By Last Name")
    '*** Create CSV file from view
    outfile = "c:\ExcelExportTest.csv"
    Open outfile For Output As #1
    ForAll row In csv.CSVArray()
        Print #1, row
    End ForAll
    Close #1
    '*** Create HTML table and save as .xls to open in Excel
    outfile = "c:\ExcelExportTest.xls"
    Open outfile For Output As #2
    Print #2, "<table>"
    ForAll row In csv.HTMLArray()
        Print #2, row
    End ForAll
    Print #2, "</table>"
    Close #2
End Sub

Should everyone be a programmer?

Posted on April 2, 2013 by Karl-Henry Martinsson Posted in Generic, Programming 5 Comments

For years, there has been a debate if anyone can (or should) learn programming or not. While reading the Notes and Javascript groups on LinkedIn, as well as the Notes forums on IBM developerWorks, I have read more than one post where someone wants to learn Javascript or Notes programming, but don’t have any programming experience/knowledge.

Can anyone learn to program? No. I would say half the population could learn at least the basics and mechanics of programming.  So should everyone of those learn to program? In my opinion, absolutely no. Remember, it is widely considered that it takes about 10 years or 10,000 hours to be good at skills like  programming or playing an instrument. A majority will not invest that time in practicing unless they really have the passion.

I think you also need to have a special mindset to become a good programmer. If you learn to program just because you think it is a good career, or something that will pay you a decent salary, but you don’t have the deep interest or the right aptitude, then you will most probably not be a good programmer.

I’m still wondering: why do people who can’t write a simple program even entertain the idea they can get jobs as working programmers? Clearly, some of them must be succeeding. Which means our industry-wide interviewing standards for programmers are woefully inadequate, and that’s a disgrace. It’s degrading to every working programmer.

At least bad programmers can be educated; non-programming programmers are not only hopeless but also cheapen the careers of everyone around them.

Jeff Atwood, Coding Horror

 

Passion

A sign of a good or great programmer is passion. You must be really interested in it to be good at it. Anyone can learn to drive a car, but you need passion and dedication to become a Nascar or F1 driver. This is what drove me to spend hours every day after school in the computer room, until the school closed for the night and I was kicked out. I did not have a computer at home, so this (together with the breaks between classes) was my only chance to practice programming. I wanted to learn, to be good at it, to get the computer to do what I wanted it to do. I wanted to find a problem and solve it, and then find a better way to solve the same problem, until I was satisfied I had the best solution I was able to create.

 

Problem Solving Skills

When you are a programmer, no matter what level, you need to be able to solve problems. If you are a junior programmer, you might get a task assigned to you by a more senior developer, but you still need to break down that task into smaller parts and solve the problem.

After a fair bit of trial and error I’ve discovered that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.

So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK. An example of a Fizz-Buzz question is the following:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes. Want to know something scary? The majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.

Imran Ghory, Imran on Tech

 

Logical and Abstract Thinking

This skill goes hand-in-hand with problem solving. You must be able to think though a problem and look at the logic behind it. What tasks/steps are being done in what order? What holes are there in the process? Where could things go wrong? You must be able to anticipate where errors might happen and put in preventive code for that.

 

Technical Knowledge and Interest

You need to understand the platform you are working with. For Notes and Domino this means understanding about views, forms, documents, as well as the Domino Object Model. For Javascript it means understanding the browser Document Object Model.

You also need to understand the limitations of the platform, and how code is handled internally. A typical example is how new Notes developers still often use GetNthDocument(), because they don’t understand how it works. In most cases, GetFirstDocument/GetNextDocument() is the preferred way to loop through a collection. Yes, there are some cases where GetNthDocument() can be used without any degradation in performance (I believe in a ordered collection, i.e. the result of FTSearch), but to avoid confusion, I alway recommend new Notes programmers to avoid using that specific function altogether.

But you also need to know about related technologies. If you only know Lotusscript or Formula language, you will have a much harder way to integrate with other systems. In the case of Notes, you need to know about XML, COM, HTML, CSS, Javascript and JSON, and understand what Ajax and REST are and how to use them. Knowing — or at least understanding — Java is also a plus. For Javascript, you need to know HTML and CSS well, in addition to the browser DOM. Each language and platform has its own set of skills you need to have some knowledge about.

Finally you need some basic match skills, as well as knowing your language. If you don’t know about the Modulo operator (available in all programming languages I know), you will struggle with your Fizz-Buzz code…

 

Aptitude

This is really a combination of everything listed above. Either you have it, or you don’t. You can’t teach aptitude.

Despite the enormous changes which have taken place since electronic computing was invented in the 1950s, some things remain stubbornly the same. In particular, most people can’t learn to program: between 30% and 60% of every university computer science department’s intake fail the first programming course. Experienced teachers are weary but never oblivious of this fact; brighteyed beginners who believe that the old ones must have been doing it wrong learn the truth from bitter experience; and so it has been for almost two generations, ever since the subject began in the 1960s.

Saeed Dehnadi and Richard Bornat, School of Computing, Middlesex University

 

So if you don’t have passion and aptitude for programming, perhaps you should consider some other type of work? The world don’t need more programmers who can’t program. But we need to find the ones that have the aptitude and passion and help them become better programmers, or at least give them the chance to learn.

Luxor ABC 80 computer

The year I started 7th grade, a computer club was founded in my school. I had never programmed before, but I liked technology and had a cousin who worked as an engineer at Hewlett-Packard in Sweden, so I joined the club from the beginning.
In order to get an access card to the computer room, we had to take a couple of evening classes in Basic programming and general computer knowledge. While I was waiting for the classes to begin, I went to the library and borrowed a book on programming, read it and wrote programs in a notebook, just to understand the principle. When the classes started, I already had a good idea about how it worked, and soon I was spending all my free time after school in the computer room.

Atlas – My graduation project in High School

Over the next 6 years, I spent probably an average of 3 hours per day writing code, understanding how the computers worked, testing and learning different programs, and exchanging ideas with other and older students. I even choose programming (combined with geography, another favorite subject of mine) to be the subject of my graduation project. Together with my best friend, we calculated that we spent about 800 hours on the project. It even involved me writing a graphics program first, to allow us to draw the maps to use in the program…

We need to give the students of today, starting already in Middle School, the opportunity to learn programming. They need teachers with real work experience as programmers, not just theoretic experince. I know that for example Bruce Elgort (well known in the Lotus/IBM community) is teaching programming at Clark College in Vancouver, WA. But I think we need to find the students with aptitude for programming much earlier and help them become successful.

Perhaps with better education in the US, there would be less of a need to import foreign workers on H-1B visa. Or at least the companies would have a harder case to argue for importing less costly workers from India and China if there were enough good programmers already living in the United States to hire.

 

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
  • …
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • Next

Administration

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

Tracking

Creeper
MediaCreeper
  • Family Pictures
© TexasSwede 2008-2014