Glen Urban's Notes/Domino/XPages Blog

 
alt

Glen Urban

 
Glen Urban is a XPages / Lotus Notes/Domino developer/system admin located in the North East of England. He works for IBM Advanced Business Partner FoCul.

Notes Doclinks going to the wrong server?

Glen Urban  May 19 2011 02:02:02 PM
When you generate emails with doclinks are users complaining it takes them to a server on the other side of the world? If so, take a look at the Catalog on the server specified as the "Catalog/domain search server" in your Location Document. Look at the "Applications by Title" view. Are there multiple servers listed for the application (database) where the doclinks came from? This could be a problem...

What Should Happen With DocLinks?

This technote from IBM lists the steps Notes takes to determine which server to use:

1) Use the icon for the replica on the user's workspace if one exists.

Assuming the user hasn't opened the application before then they won't have an icon on their workspace so the search goes to step 2.

2) If using Catalog/Domain Search, this will be used to locate* a replica.

This is further qualified by the statement: The search will open the catalog and find the "best" server choice containing a replica, searching by server name alphabetically. The best choice considers server availability.


A Potential Problem

When the search gets to step 2 you may be using, for example, server "USA1" but if the first server under your application in the "Applications by Title" view is called "AUSTRALIA1" then the doclink will be opened on AUSTRALIA1. I've also seen this cause embedded views to open on the wrong server and @DBlookups, where the database was specified using a replica ID, to lookup to the wrong server.

What about the statement The best choice considers server availability ? The technote doesn't elaborate on how Notes evaluates "availability". I suspect it chooses the first server in the same Notes Network. In the organisations that I've come across this problem all the servers we're in the same Notes Network (which is probably not recommended).

How Can I Fix It?

I resolved this by re-configuring the catalog to show only applications that have replicas on that server. For example, on server USA1 the catalog would only list replicas found on USA1. So when the Notes client looks for the location of an application in the catalog (step 2 above) it will always return a replica on USA1. In a typical Hub and Spoke topology this can be achieved using the ACL of the catalog. On the spoke servers, e.g. USA1, I ensured the Hub server is restricted to reader access and USA1 had manager access. This prevented the Hub server from adding entries to USA1's catalog but allowed it to read them and compile a full list of all applications, and their servers, on the Hub.

This solution resolved the issue for new users, or existing users opening applications they hadn't used before. But it didn't resolve the problem where users already had icons on their workspace that point to the wrong server. In this instance you can write code to re-stack the workspace icons, for example, something like this from Tommy Valand.

A Word of Warning About Testing

If you delete all the workspace icons for an application and then change the catalog server specified in your Location Document then you may think that Notes should start looking in the new catalog. But it doesn't! Even if you delete desktop8.ndk and bookmark.nsf Notes will still remember where it's been before. If you look at the document properties for your Location Document then you'll find several fields that are used for caching e.g. $LastFileNames and $StackFileNames. There's all sorts of caching going on in there. So it's best to delete desktop8.ndk, bookmark.nsf and create a new Location Document. This does make testing a pain!

Image:Notes Doclinks going to the wrong server?

XSP.isViewPanelRowSelected: How to confirm if documents are selected in your XPage view control

Glen Urban  May 16 2011 11:47:45 AM
How do you make your XPage buttons work like the standard "Simple Action" Delete button and prompt you if you haven't selected any documents?

If you look at the HTML source of an XPage with a delete button you will see a call to XSP.isViewPanelRowSelected. This accepts two parameters, the first being the name of your view control. If you don't change the default this will be "viewPanel1". The second parameter, I believe, is referring to the actual tick boxes in the view control. So far I haven't needed to change this from "_colcbox".

So here's an example for an "Approve" button...
Image: XSP.isViewPanelRowSelected: How to confirm if documents are selected in your XPage view control

Any server side JavaScript won't get executed unless there a documents selected and you have confirmed you wish to continue.

You can find out more about the XSP JavaScript Library here

XPage: Unresolved compilation problem: The code for the static initializer is exceeding the 65535 bytes limit

Glen Urban  February 3 2011 02:27:18 PM
When adding an XPage front-end to an existing Notes client application I came across the following error message previewing the XPage:
"Unresolved compilation problem: The code for the static initializer is exceeding the 65535 bytes limit".

The original Notes form had lots of fields on. My new XPage worked at first but I hit the error as I added more fields. It looks as though I hit a Java limitation. Splitting the XPage fields onto separate Custom Controls resolved the problem.

Shared Actions Not Replicating?

Glen Urban  February 3 2011 02:02:11 PM
I came across a strange problem where modifications to existing Shared Actions, and new Shared Actions, did not replicate from local replica to server, or from server to server. After a lot of head scratching a view of design elements helped me track down the problem. Kevin Petit first made me aware of how to create such a view on his blog here.

All the Shared Actions in a database are stored in one Note. But if you look at the screen print of the design elements view below you can see two "Notes" (documents) for Shared Actions. Some how a replication or save conflict had occurred. Notes seemed to pick at random which set of Shared Actions to use in separate databases.

Image:Shared Actions Not Replicating?

Deleting one of the Shared Action documents resolved the problem.

IsArrayInitialised()

Glen Urban  August 4 2010 11:56:42 AM
Surprisingly LotusScript doesn't provide this but here's a function to test if a dynamic array is initialised.

Function IsArrayInitialised(a As Variant) As Boolean
 'returns True if an array is initialised
  On Error Resume Next
  IsArrayInitialised = False
  IsArrayInitialised = (Ubound(a) >= Lbound(a)) ' will generate error if not initialised    
End Function

NotesDatabase.Server Inconsistency

Glen Urban  April 13 2010 02:42:32 PM
Consider the following LotusScript code
Dim session As New NotesSession
Print session.CurrentDatabase.Server


Would you expect the server name to be in an Abbreviated (e.g. SERVER/GB/ACME) or Canonical format (e.g.CN=SERVER/OU=GB/O¬ME )?

The answer is "it could be either": I experienced a problem in some code that depended upon this property, on one Notes client it evaluated to an Abbreviated name and on another to a Canonical name. Both clients were 8.5.1. Both running on the same server. The only obvious difference was that the designer client was installed on one client machine but not the other.

I resolved the problem by forcing a conversion to a canonical format so that the code worked regardless of how database.server decided to return the name.

Has anyone else experienced this problem?

notesUIWorkspace.RepaintScreen()

Glen Urban  March 11 2010 03:21:34 PM
Ever wished you had a method to repaint the screen?

Recently I was working on some automation with Microsoft Word and wanted to display a message to the user warning them that the processing may take a while. I used a hide-when formula to display a message on my form but I found that the screen did not repaint correctly. Some controls on the form that should have been hidden were still displayed.

As far as I know there is no way in LotusScript to repaint the screen. To resolve this we can make a call to Windows to do the refresh for us.

Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Integer
Declare Function UpdateWindow Lib "user32" (Byval hWnd As Integer) As Integer

Sub RepaintScreen
On Error Resume Next
Call UpdateWindow(GetActiveWindow())

End Sub

Dynamically Hide/Display Rich Text Fields

Glen Urban  January 9 2010 02:34:09 PM
Many Notes developers are aware of the problems with using Hide When formula on Notes Rich Text fields. It can have unpredictable results on the contents of the field, these are detailed in an IBM Technote here. In that note two solutions are proposed 1) use a computed Subform and 2) use a Controlled Access Section.  But these solutions are not without their problems.

On reading this blog entry it suddenly occurred to me that using a Layer could offer a better solution.
1) Create a Layer and place the Rich Text Field on that layer.
2) When you create a layer you will see that it has a Layer Anchor. You can set a Hide When formula on this anchor.

The advantages of this approach are:
1) The Hide When is not on the Rich Text Field so no unpredictable results
2) You can hide/show the Layer/Field dynamically. In the screen shot below I have used a Radio Button that can show/hide the Rich Text field.


Image:Dynamically Hide/Display Rich Text Fields

Dojo Samples

Glen Urban  December 1 2009 03:45:44 AM
If you are are looking for Dojo samples then you don't have to go far. With 8.5.1 the Dojo 1.3 toolkit and samples are installed with the designer client and server.

Dojo is installed in the data folder: data\domino\js\dojo-1.3.2\

If you browse through the folders you will see that there is a convention to add a tests folder with samples. Within this folder the samples are zipped into a file called tests.zip. Simply extract the zip file to see the sample web pages and code.

So, for example, if you wanted to see the charting samples you would extract the zip file data\domino\js\dojo-1.3.2\dojox\charting\tests\tests.zip

Remember when you preview (not just open the file) in your browser, replace domino\js with domjs. So if you wanted to preview the 2D pie chart sample on your local client you would use the following url: http://localhost/domjs/dojo-1.3.2/dojox/charting/tests/test_pie2d.html

One thing to be aware of is that if you try to open runTests.html it won't work because it references a file that is not in this version of the Dojo toolkit. You need to open each sample separately.

How to add a Dojo Chart to a Domino Form

Glen Urban  November 25 2009 09:27:49 AM
Creating a Dojo chart in Domino took a step forward with release 8.5.1. When you install or upgrade a Domino server Dojo 1.3.1 comes as standard.

If your looking to get started on Dojo charts then you should take a look at this guide on sitepen: A Beginner’s Guide to Dojo Charting.

The following builds on the code shown in that guide and describes how to add a Dojo chart to a Domino form. The JavaScript below needs to be in the JavaScript Header. I used pass through HTML on to my Domino form so added an opening and closing <head></head> tag (at the start of step 1 and the end of step 3).

1. Include a reference to the Dojo library

<head>
<script type="text/javascript" src="/domjs/dojo-1.3.2/dojo/dojo.js" djConfig="locale: 'en-gb', isDebug:false"></script>

2. Populate your JavaScript Variables from your Domino Data

<script type="text/javascript">
var fc = "<Computed Value>" ; // the Fill Color for the columns
var sc = "<Computed Value>" ;// the Stroke Color i.e. column outline colour
var series1 = [<Computed Value>]; // an array of data for the chart
var xlabels = [<Computed Value>]; // an array of x axis labels
</script>

Because I have written pass thru HTML on my form I can use Computed Text to reference data in my Notes application. For example, the formula within the Computed Text used to define variable fc is just "lightblue". This could easily reference a field on the form or do a look up to a configuration document.

Variable series1 needs to be an array. Here the Computed Text references a multi value field on my form. Again this field could look up data on the same form or elsewhere in your database. Keep in mind that JavaScript arrays are delimited by commas so this should evaluate to something like "1, 9, 9, 3, 5, 3, 2, 7, 9, 10"

The xlabels variable is a bit more complicated. It needs to be formatted like this:
{value: 1, text: "a"}, {value: 2, text: "b"}, {value: 3, text: "c"}, and so on...

To achieve this I have a multi value field on my form that lists the x axis labels i.e. "a":"b":"c":"d":"e":"f":"g":"h":"i":"j".
The Computed Text uses the following @Formula to parse it into the format necessary for Dojo.
@For(n :=1; n<=@Elements(XaxisLabels); n:= n + 1;
lblTxt := @If( n=1;
                        "{value: " + @Text(n) +  ", text: \"" + XaxisLabels[n] + "\"}" ;
                       lblTxt : (  "{value: " + @Text(n) +  ", text: \"" + XaxisLabels[n] + "\"}" )
                                )
);
lblTxt

3. Add the JavaScript code that will generate the graph

<script type="text/javascript">
dojo.require("dojox.charting.Chart2D");
var chart1;
makeCharts = function(){
chart1 = new dojox.charting.Chart2D("simplechart");
chart1.addPlot("default", {type: "Columns" , gap: 2});
chart1.addAxis("x" , {labels: xlabels  } );
chart1.addAxis("y", {vertical: true , min: 0});
chart1.addSeries("Series1", series1 , {stroke: {color: sc, width: 2}, fill: fc } );    
chart1.render();      
};

dojo.addOnLoad(makeCharts);
</script>
</head>

4. Add a HTML Div tag to your form

Now all that's needed is to place a div on your form, using pass thru HTML, wherever you want your chart to appear. Alter the height and width options to specify the size of your chart.
<div id="simplechart" style="width: 500px; height: 250px;"></div>


The resulting chart will look something like this
Image:How to add a Dojo Chart to a Domino Form
This chart is very basic and there is much more you can do with Dojo: multiple data series, 3D charts, stacked charts and so on.