Thursday, December 20, 2012

Using indexOf method on array in server side JavaScript

Sometime back I was trying to use indexOf method on an Array object in server-side JavaScript (SSJS) code. But it was giving me error that indexOf method is not defined. I also couldn't find this method in help documentation. It was then it struck me that the implementation indexOf method in client side JavaScript itself is a bit fuzzy with Internet Explorer not supporting it. It can be defined using prototype property.

I found a simple solution here which implements the method. Just add the below code snippet to your SSJS code and then you would be able to use indexOf method.


Remember that this would be required for SSJS. For client side JavaScript I would recommend using dojo.indexOf.

Wednesday, December 19, 2012

Charging pattern on HTC One X

My HTC One X has a pattern in which it charges itself.


In the above screenshot of my battery usage you can see that from 10% battery level to 60% battery level my phone charges at a constant rate. But from 60% up till around 75% this rate dramatically drops and it takes much longer to charge. Then picks up again until around 90% and afterwards it charges very quickly. I don't know why does this happen and what is its significance. I contacted HTC support but there response was not satisfactory either.

So if you notice the same pattern while charging or a different one do post it in the comments.

Sunday, December 9, 2012

New features in HTC One X after Jelly Bean update

Some time back I updated my HTC One X to Jelly Bean (JB) using OTA update. The update takes your Android version to 4.1.1 and Sense to 4+.


Its been almost a 2 weeks with this update and the most noticeable improvement I can see is of battery usage. My phone lasts 1-2 hours more than it used to before. Well done HTC! There also some additions (and deletions) which I am going to describe here. Now I not an Android expert so I don't know all the new features in JB itself, so you may find a feature new in JB listed here. Also you won't find Google Now and Google Play Music here as I know they are new to JB and not HTC One X.

Sunday, December 2, 2012

Making internet pass-through work after updating HTC One X to Jelly Bean

Update 22 Jan 2013: "HTC Sync" seems to have been discontinued so the download links given below will not work. "HTC Sync" is different from "HTC Sync Manager". For exact difference read on.

I recently upgraded my HTC One X to Jelly Bean via OTA update. After updating I was unable to use internet pass-through which used to work flawlessly before and I already had HTC Sync installed on my PC. I uninstalled, installed, uninstalled again and installed again to make it work. But it simply refused. It gave me error of "Either you do not have the latest version of HTC Sync installed on your PC, or another phone is already using Internet pass-through on your PC." on my phone.


From this discussion on XDA Developers forum I found that there is something called as HTC Sync Manager. This is different from HTC Sync which I had installed on my machine. I don't know why HTC did this but its really confusing. Here's how these two software look.

Wednesday, November 21, 2012

Adding caption to image in form

When you add an image on to your form in Lotus Notes you can specify a caption for that image. In the image properties you will find this option along with where do you want to position this caption.


I usually use this technique to put text on fancy button images. So with just one image resource I can have multiple buttons with each having different text on it. You can even change the font by clicking on the image and then setting font properties in toolbar.



Some limitations of this technique are that the caption cannot be computed and it does not work on web.

Thursday, November 15, 2012

Drag out file links from download control to save just like in Gmail

Google adds a lot of interesting features in it products. One of them is dragging a file link in your Gmail on to your desktop (or a folder) to download it. This article on CSS Ninja explains exactly how it is done.

We can also put this feature in our download control so that each file link can be dragged on to your folder to start download without going through save dialog.

Step 1: Identifying the file links in a download control

This is actually pretty simple. XPages by default sets the class name of the file links in download control to xspLinkFileDownload. So all you need to do is to use a simple dojo.query to find all those link and loop through them.

Step 2: Adding attributes to anchor tag

Now you need to set two attributes in the anchor tags of file links - draggable and ondragstart. The draggable attribute needs to be set to true, that's all.

Setting ondragstart requires a bit more details. You need to call event.dataTransfer.setData("DownloadURL", "application/octet-stream:<FILE NAME>:<FILE DOWNLOAD URL>"). Note that while specifying <FILE DOWNLOAD URL> make sure its the complete path start from http://. These attributes can be set using dojo.attr.

So your final JavaScript code looks something like this:


One limitation here is that this only works for Google Chrome. I have put this script block on XSnippets here. Just copy it from there and put it into your XPage.

Friday, October 26, 2012

Getting resources in database as stream in XPages (SSJS / Java)

Some time back I was trying to get the resources in database (to be precise image resource) in my SSJS / Java code. I tried a lot of options like ClassLoader.getResourceAsStream, MyClass.class.getResourceAsStream but no success. Then today while going through the sample database of Extension Library I ran into a piece of code which got the image resource as stream using a single line of code.


As simple as that. In case of Java you would write like this:


In my tests this worked for getting image resources, file resource and style sheets as streams.

Saturday, October 20, 2012

Using dijit.form.CheckBox in check box group in XPages

dijit.form.CheckBox adds a fancy styling to the plain check box, which I love. Adding it to a single check box is pretty straight forward. Just set the dojoType property of the check box to dijit.form.CheckBox. But in case of check box group its not that straight forward.

When a check box group is rendered in browser it is rendered inside <fieldset> tag. So setting the dojoType property doesn't give the desired result. You need to set the dojoType property individually on each of the check boxes in the group. Fortunately, all the check boxes share the same name so they can be targeted using simple dojo.query.

Let's say the name of your check box group is "checkBoxGroup", then just add this script block to your XPage:


Make sure you place this script block after your check box group. Needless to say that you need to add dijit.form.CheckBox in your XPages resources as Dojo module.

You can also extend this technique to set dijit.form.RadioButton in radio button group.

Saturday, October 6, 2012

Error of "Invalid field name" while saving form

While working on a legacy Lotus Notes client based application, I did some modifications on a form but while trying to save it I was getting error message "Invalid field name" and the form simply refused to be saved. I checked all the field names trying to find out any invalid character amongst them, but no luck.

So I went to my faithful old friend — Google. And it took me to this discussion on Notes/Domino 8.5 Forum where a user was having the same issue. He resolved it by removing and adding existing sections. Why it happened, he didn't know.

Friday, September 28, 2012

Other ways to use @DeleteField

The help documentation of @DeleteField only displays one way on its usage:


But recently while working on an application I found out that there are other ways in which this command can be used.


Would love to hear if you know any other ways to use the command?

Thursday, September 6, 2012

Expand / Collapse particular category in a view in XPages

In XPages, you can expand all / collapse all categories in a view either using the expandLevel property of view control or using view control API. The API technique can further be extended to expand / collapse a particular category in a view. So to expand the code goes like this:

Saturday, August 25, 2012

Get all field values in a document

Sometimes for debugging I am required to check all the field values in a document. It can get tiresome (and boring). So for this purpose I had created a small formula code snippet that would loop through all the fields in a document, get its values and put it in an email to the current user. I simply put this in a toolbar button of my Notes client and its good to go. Here's the code:

Thursday, August 23, 2012

Reading Windows registry from Lotus Notes using formula

I can't remember what exactly I was searching for when I ran into this question on N/D 8.5 forum which introduced me to the function @RegQueryValue. Basically this function allows you to read the Windows registry.

So if you want to read CPU information on a particular machine then you would write code as:


Unfortunately I couldn't find any function to write registry value.

Monday, July 30, 2012

Using extension library component Remote Service

Recently I had some queries on using the extension library component of Remote Service a.k.a. <xe:jsonRpcService>. I posed this question on StackOverflow and Tim Tripcony gave a detailed answer along with some operations where this might be useful. I would strongly suggest going through Tim's answer.

Friday, July 27, 2012

Creating optgroup tag in combo boxes in XPage

Tommy Valand in his blog post pointed to a StackOverflow question to add <optgroup> in combo box in JSF. Using hints from there I was able to devise a way to get <optgroup> in combo box for XPages. Below is the code snippet for the combo box.

Wednesday, July 25, 2012

Getting stack trace of error in LotusScript

Java has a wonderful method called printStackTrace which prints out the entire stack trace in case of exception. Unfortunately LotusScript does not have any similar functionality. But we can use On Error statement to reproduce this functionality.

Friday, July 13, 2012

Customizing lock screen shortcuts on HTC One X

On my HTC One X I was trying to customize the icons which are present on the screen when it is locked.


After a bit of searching and experimenting I realized that these icons come from the launch bar.


So you have to customize the launch bar and the same four icons will be visible on the lock screen.

Tuesday, June 19, 2012

Editable authors field will auto-populate with current user's name

While working on a Notes client based application, I came across an interesting scenario. Let's say you have an editable Authors field on your form. If you open that form in Lotus Notes client then the current user name automatically appears in the field. But if you put in the field's name itself in the Default value formula then the field appears blank. My tests concluded that, this behavior is shown only by Authors field and not Readers field. Plus, I couldn't find this behavior documented in the help documentation.

Tuesday, June 12, 2012

Improving battery life of HTC One X

HTC One X is an amazing phone and has got pretty good reviews from The Verge, Engadget and Gizmodo with Sharif Sakr from Engadget even going on to say that "No matter how hard it[Samsung Galaxy SIII] tries, it just isn't greater than the sum of the HTC One X's parts". I bought it myself and have been using for around 3 months now. But one really troubling aspect with this phone is its battery life which is further exacerbated by the fact that you cannot remove the battery of this phone. While HTC claims significant performance improvement in its battery, the phone seems to discharge very quickly and charge very slowly. So here are some tips to improve and conserve your battery life.

Updated 22 Jun 2012: Avoid using live wallpapers
Updated 5 Oct 2012: Limiting background processes and Setting network mode

1. Fully charge your phone before turning it on for the first time

This is is very important and there are people who have suffered because of this. If you didn't there is a good chance that your battery life would be poor. But all is not lost, follow these simple instructions to recalibrate your battery.

Monday, June 4, 2012

Displaying common names of user with Name Picker

I have been trying out Extension Library and I must say I am really impressed with it. One of my favorite control there is Name Picker. The only problem with that is the input control whose value is set by name picker needs to be in edit mode and it shows the selected names in abbreviated format. In one of our application we wanted to show common names and the input control to be non-editable so that user could not play around with values.

Wednesday, May 16, 2012

Taking screen capture in HTC One X

A simple trick to capture your screen in HTC One X which I got from here - press and hold power button and then press . The screen is saved in the Camera shots album in Gallery. And you don't need to install anything  from Google Play!

Wednesday, May 9, 2012

Pass server side javascript code to custom control

Some time back I was trying to pass server side javascript to a custom control and then get the code executed from click of a button inside the custom control. With help from Sven Hasselbach I was able to do it. But the problem in that approach was that your entire code has to written in a string literal which denies you the flexibility of the javascript editor. Experimenting a bit more I stumbled on another solution which I think is better.

For custom control property select Type as "Simple Actions > Execute Script".

Tuesday, May 1, 2012

Showing additional controls in your Domino Designer

By default the Domino Designer only shows limited controls in Controls view. Some controls have to be accessed from "Other..." like the Hidden input and Output script.


To show this controls in the Controls view go to "File > Preferences" in your Domino Designer.

Tuesday, April 17, 2012

Grappling with "Ignoring portion of document that uses a feature from another version of Notes"

In one our databases, whenever we were trying to open a document it used to give us an error of "Ignoring portion of document that uses a feature from another version of Notes". We were able to see all the fields in document properties, even able to extract all the attachments in it using LotusScript code. But document was simply refusing to open in the UI.

A little search and we found this technote which details out the reason and possible solutions to get the document opened. One of them included deleting the problematic rich text field. YIKES!

But what eventually what helped us was this intelligent suggestion by Cathy Fitzherbert. Just open the document in a browser in edit mode and save it. Then you can successfully open it in your Lotus Notes client. On the downside, you lose all the formatting in your rich text field and all the attachments will start to appear at the bottom of the document.

Wednesday, April 11, 2012

Use replica ID in @DbLookup with caution

Few days back I was faced with an issue where a user reported the following error message while opening a form in Lotus Notes client:

Field '<FIELD NAME>': Connection denied. The server you connected to has a different name from the one requested.

While this thing was working at almost all other machines (including mine), it was just one user where it was not working. The formula on the field was a single line database lookup as:


After unsuccessfully going over technotes, forums and blogs I went back to help documentation for @DbLookup and something caught my attention.

Monday, April 9, 2012

Installing and running XPages Extension Library in your local machine

I had been hearing a lot about XPages Extension Library and finally got to try it out in XPages code-a-thon held at Mumbai. So I decided to try it on my local machine along with little help from experts on StackOverflow. Its a simple two-step procedure - install extension library and run extension library.

Install XPages Extension Library

First of all get the latest release of extension library from OpenNTF. Unzip the file and find "updateSiteOpenNTF-designer.zip". Unzip it and you will get two folders of "features" & "plugins" and a file "site.xml". In Lotus Notes sidebar, go to My Widgets and select "Options > Configure a Widget from... > Features and Plugin on an Update Site". If you are unable to see My Widgets in your sidebar then click here.


Saturday, April 7, 2012

Enable "File > Application > Install..." in Lotus Notes

Mary Beth Raven in her blog here shows how to enable "File > Application > Install..." in Lotus Notes. Just you go to "<Lotus Notes folder>\framework\rcp", find a file "plugin_customization.ini" and add a line com.ibm.notes.branding/enable.update.ui=true in the file.


But based the screenshot provided on her blog I guess she didn't ran into a specific problem, which I did, because she was using Windows XP. Basically if you edit the file plugin_customization.ini and try to save it you will get an error saying "Cannot create the C:\Program Files\IBM\Lotus\Notes\framework\rcp\plugin_customization.ini. Make sure that the path name are correct."

Displaying My Widgets in your sidebar in Lotus Notes

To display My Widgets in your sidebar panel, go to "File > Preferences...". In the Widgets tab enable the option of "Show Widget Toolbar and the My Widget panel".


Tuesday, March 20, 2012

Export Lotus Notes documents to Microsoft Word

For a requirement I was looking for exporting Lotus Notes documents to Microsoft Word. I found some help here and here. The former one uses Word.Application while the latter does something with user32.dll. But I was looking for something which was not dependent on external software. Then I came across @Command([FileExport]). A little help from the discussion here, I was able to devise a simple solution to it.

Lets say, you have a form fUserProfile that you want to export to a Word file. First create a copy of that form and name it, say, fUserProfile_Export. In PostOpen event of the fUserProfile_Export form enter the following formula.


Get the text back on Gmail buttons

Ever since Gmail launched its new look there have been some positive, some negative and some extremely negative reactions. But what I really hated was the fact that now there were only icons present instead of labels on the buttons. Worse, there was no way to get it back!


But now Google has finally added a setting so that you can get the text back on buttons. On the top-right you will find gear icon (Settings), click on it and from the popup menu click on Settings.


Saturday, March 3, 2012

24Online client crashes with Avast antivirus

Recently when I moved from AVG antivirus to Avast antivirus, I couldn't use my 24Online Client as it used to crash every time I started it. The only way to start it was to disable Avast, start the 24Online Client and then enable Avast again. A real pain! After a bit of trial-and-error I found the solution.

Go to the main screen of Avast. From there go to "REAL-TIME SHIELDS > Web Shield". Click on the "Expert Settings button".

Tuesday, February 28, 2012

If Rajinikanth was a software engineer... :)

I know that there is no shortage of Rajinikanth jokes, but I couldn't stop myself after reading this post. So here it goes.

If Rajinikanth was a software engineer...
  1. Compilers don’t warn Rajinikanth. Rajinikanth warns compilers.
  2. Rajinikanth writes directly in binary. He then writes the source code as a documentation for other developers.
  3. Rajinikanth can derive private key by just looking at the public key.
  4. All pointers point to Rajinikanth.

Thursday, February 23, 2012

Image URL in XPages using Notes client and browser

In Java Charts, one of the users reported that charts were not visible in Notes client. The charts (images) are basically being generated using the XAgent technique, and you will face the same problem if your image is being generated using XPage.

To understand what exactly is happening lets take help of an example. Say you have XPage with following code snippet which displays an image using javascript formula. (actn005.gif is present in the current database as image resource.)


Saturday, February 11, 2012

Google removes plus sign on new tab button in Chrome 17

Just updated to Google Chrome 17 (to be precise 17.0.963.46 m) and there are some UI enhancements that Google has made, like this one.


Yup, they did away with the + (plus) sign on the new tab button. I kind of liked the plus sign and at first it left me confused, thinking it was a bug (I was not alone). I also couldn't find this in Google's Stable Channel Update for Chrome 17 except in the user comments.

Update 12 Feb 2012: Just found this link which basically suggests that this new look was being planned as early as 27 Sep 2011 in Chromium. It even goes on to suggest how you can get the plus sign on new tab button back.

Calling inner classes and enum from SSJS

While working on RSS Reader custom control for OpenNTF I had got stuck when trying to use enums. Basically I wanted to call the enum Proxy.Type to create instance of Proxy class. In Java you would write the code some thing like this:


But to write the same code in SSJS you need to concatenate the class and enum with $ (dollar) symbol. So your SSJS code would be:


The same goes when you are dealing with nested / inner classes. But why use the dollar symbol? I am not sure of the exact reason, but when a Java class with inner class or enum is compiled it generates two class files - one for outer and one for nested. For e.g.


The above class would generate class files as OuterClass.class and OuterClass$InnerClass.class.

Friday, February 3, 2012

Never update agent properties using web helper agents

Well... had a hard day today. But I have only myself to blame.

We had 100+ databases which were recently moved to a new server. So we had to update the "Run on" property of the agent to the new server. That can't be difficult! Just write a helper agent that will update all those agents using the ServerName property of NotesAgent class. I did just that, made it a little bit generic by adding configurable parameters. As their were a lot of databases to be updated I decided to run this agent on the server using the OpenAgent URL command. BIG MISTAKE!

Tuesday, January 31, 2012

Disable encryption while creating new databases

My friend was facing a problem that while creating new databases in the New Application dialog the encryption settings were being set to "Locally encrypt this database using Medium Encryption".

Friday, January 20, 2012

Tuesday, January 17, 2012

View XPage source code in browser

Karthikeyan A had written in his blog about viewing your XPage source code in browser. You just needed to add a plus (+) sign in front of your XPage URL and it would show you the source in the browser. Tommy Valand confirmed that this bug was fixed in Domino 8.5.1 FP1.

But recently, while playing around with XPages I found out that there is yet another way where you can get the source code in browser. Open the XPages view in Domino Designer and go to "Properties > Document Ids". There you will find Note UNID. Copy it.


Now create URL as http://<SERVER NAME>/<DATABASE PATH>/<Note UNID>. For e.g. http://myserver/mydatabase.nsf/14C2FD8F53CD42204925791600131817 and run it. You will find your XPage source code in the browser if you are using IE else you will be prompted to download a file which would contain it. I tried it on Domino 8.5.1 FP2.

Of course you need to know the Note UNID of XPage for this, which might not be possible for an end user... PHEW!

Sunday, January 15, 2012

Add custom icon to dojo button in XPages

Adding icon to a dojo button is pretty simple. Jut set the dojo type to dijit.form.Button and add a dojo attribute named iconClass with value dijitEditorIcon dijitEditorIconCut.


And you get something like this:

But what if you want your own custom icon to appear on the button? The Dojo Themes and Theming Documentation explains about using custom icons. First of all import the icon image in your database. Now create a style sheet with following CSS class.

Saturday, January 14, 2012

Dash search in Ubuntu / Unity

When I first upgraded to Ubuntu 11.04 I took an instant disliking to its new desktop environment - Unity. But sadly I was really out of choice as GNOME 3 was even more disappointing (they even decided to do way with minimize and maximize buttons). Unity in Ubuntu 11.10 was a bit improved but still I hated the interface. But now, I have kind of got used to it and discovered this new thing in Dash search.

In Unity you can search for applications in Dash, but what I didn't know that you could also search inside applications. Basically I wanted to change the theme so I went to Dash and searched for "theme" and look what it gave me in results.


Saturday, January 7, 2012

Declaring global variable in XPage using dataContexts

While working on a XPages application I required a database object to be initialized and then used in various controls in XPage. I wanted to initialize the object only once then use it again and again. With some experimenting I found out that if I put the initialization code in beforePageLoad, afterPageLoad or beforeRenderResponse I was able to access the object from anywhere in XPage. But I wasn't sure that whether this was the correct way or the objects would get automatically garbage collected. So I posted this question on XPages forum.

Paul S. Withers suggested me to use dataContexts. You can find them in All Properties tab of XPages properties inside data section.

Getting methods, fields, constructors for XPage Java classes


In my previous blog I was able to find out which Java classes were represented by global objects & functions of SSJS. For e.g. facesContext.getExternalContext() returns object of com.ibm.xsp.domino.context.DominoExternalContext. But what methods, fields, etc. are available in that class? To get those you use the Reflection API (java.lang.reflect package) in Java via which we can find out the methods, fields, etc in a class. Using this I built a small XPage which can explore these classes. Here’s how it looks:

Wednesday, January 4, 2012

Double exclamation / bang (!!) in Lotus Notes

Double bang or double exclamation (!!) is an interesting thing in Lotus Notes. It basically is an internal network separator to Notes1 used to separate the server name and database path. No wonder in older release of Lotus Notes, launching attachments which have double exclamation marks in file name would crash Notes client. Also if you try to attach a file (either from Notes client, web or XPages) with double exclamation marks in its name, then the part preceding the double exclamation marks is removed from the attached file name. So if your name of file is file!!name.txt then after attaching, your file name would be name.txt. Even using the EmbedObject method in NotesRichTextItem class attaches the file in same way.

I used it myself when I wanted to open a specific frameset in a different database. Basically where ever you find the @ button in properties, there you can specify the server & database concatenated with double exclamation marks.


Also you use it in Show Database command at the Domino server console to display database and view information on a different server. David Leedy found out that while binding XPages to external databases you need to use double exclamation. Even in the C API function of W32_NSFDbOpen(dbpath$, hdb&) you specify the dbpath$ as <Server>!!<Database path>.

Update 8 Jan 2012: Starting with Notes and Domino 8.5.3 you can set up Domino to preload XPage applications using the notes.ini entry of XPagesPreloadDB, where you specify the server and database name concatenated with double exclamation. And yes, it is present in the final release of the 8.5.3.


1. Lotus Notes and Domino 5.0.5 Release Notes (Pg 116)