xPages or not xPages

Are xPages a leading technologie ?

Obviously not. Of course Lotus has done a big effort to improve the gap between lotus notes and the today’s technologies, but they fail. The web has grown and they have choose the heavy choice of java and dojo.

What do you think ?

Coming next… dynamic class loading in lotusscript.,. stay tune !

Agent to create a backup of you names.nsf weekly

As an administrator, I often need to put me back in time to check something on the domino infrastructure. My Domino Domain is very small so I can afford to make a backup of my names.nsf every week.

This class, creat a copy of each documents of the names.nsf, zip it and attach it to a document… enjoy !


import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import lotus.domino.*;
import java.io.*;
import java.util.zip.*;

/* -----------------------------------------------------------------------------------------------------------------------
* Class : JavaAgent
* Date : 12.01.2011
* Author : Pierre Koerber
* Desc. : Permet de faire un backup du PAB et de le zipper.
*/

public class JavaAgent extends AgentBase {

public void NotesMain() {

try {

Session session = getSession();
AgentContext agentContext = session.getAgentContext();

// get the curr db
Database curDb ;
curDb = agentContext.getCurrentDatabase() ;

// (Your code goes here)
Database db ;
db = session.getDatabase(curDb.getServer(), "names.nsf") ;

DateTime timenow = session.createDateTime("Today");
timenow.setNow();

String sName = new String("") ;
String sZipName = new String("") ;
sName = db.getFilePath() ;

System.out.println("OS current temporary directory is " + System.getProperty("java.io.tmpdir"));

sName = System.getProperty("java.io.tmpdir") ;
sName = sName + "names_backup_" + timenow.getDateOnly().replace('.', '_') + ".nsf";

sZipName = System.getProperty("java.io.tmpdir") ;
sZipName = sZipName + "names_backup_" + timenow.getDateOnly().replace('.', '_') + ".zip";

// copy the database
System.out.println("Create a copy of the names.nsf =" + db.getServer() + "-" + db.getFilePath()) ;

this.deleteIfExist(sName) ;
Database newDb ;
newDb = db.createCopy("", sName) ;

// copy all the documents
DocumentCollection dc ;
Document d ;

dc = db.getAllDocuments() ;
d = dc.getFirstDocument() ;

while(d != null){

// No deletion stubs...
if (d.isDeleted() == false){
d.copyToDatabase(newDb) ;
}
d = dc.getNextDocument() ;
}

// Compress the stuff
System.out.println("Compressing file from " + sName + " to " + sZipName) ;

// delete the files if exist
this.deleteIfExist(sZipName) ;

// compress the database
this.doZipExt(sName,sZipName) ;

// create a document and attach the backup
System.out.println("Attach everything to the archive document") ;
Document doc ;
doc = curDb.createDocument() ;

doc.replaceItemValue("backupName", "Sauvegarde names.nsf of " + db.getServer() + " - " + timenow.getDateOnly()) ;
doc.replaceItemValue("Subject", doc.getItemValueString("backupName")) ;
doc.replaceItemValue("backupDate", timenow) ;
doc.replaceItemValue("agentName", agentContext.getCurrentAgent().getName()) ;
doc.replaceItemValue("Form", "backup") ;

lotus.domino.RichTextItem rt = doc.createRichTextItem("Body") ;
rt.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, sZipName, "archive") ;

// Save the document
doc.save(true, true);

// delete the database
this.deleteIfExist(sName) ;
this.deleteIfExist(sZipName) ;
System.out.println("Done");

} catch(Exception e) {
e.printStackTrace();
}
}

public void deleteIfExist(String sName){
File f = new File(sName) ;
if (f.exists()) {
System.out.println("File : " + sName + " deleted");
f.delete() ;
}

}

public void doZipExt(String sFileName, String sZipFileName) throws IOException{
System.out.println("Creating zip file :" + sZipFileName) ;

File sourceFile = new File(sFileName) ;

// Create our zip file
ZipOutputStream zipfile = new ZipOutputStream(new FileOutputStream(sZipFileName));
FileInputStream filetozip = new FileInputStream(sFileName);
zipfile.putNextEntry(new ZipEntry(sourceFile.getName()));

// Loop through the contents writing it to the zip file output stream.
int len;
byte[] buffer = new byte[1024];

while ((len = filetozip.read(buffer)) > 0) {
zipfile.write(buffer,0,len);
}

// Close the entry and the current file.
zipfile.closeEntry();
filetozip.close();
// When done, close the zip file.
zipfile.close();
}

}

show nlcache reset – reset du names lookup domino

Hello, this comand will reset the domino names.nsf cache ! it will allow the user that you’ve just put in a group to have access to an app… be careful, this command has a significant cost on your server !

Greetings

Lotus Notes : simple soft delete form your application

Hi,

In our application it’s a common task to delete document but before granting the deletion, we want to be able to discard the modification…

Here the simpliest soft delete agent in your database, it juste rename the form name which should be enough in every lotus application.

FIELD Form := "DELETED_" + Form;
SELECT @All

Just put all this code in a lotus notes agent and you’re done !

Greetings.

Easy lotusscript picklist class for your apps…

When creating your application it’s always painful to remember how to generate a picklist… here comes in play my class (which is part of my own private framework).

Which 3 lines of code, I’m doing a picklist… let me explain…

Dim pl As New DbPickList(Nothing)
pl.setView("ClasseByName")
Set docRet = pl.getSingleDocument()

The first line allows you to create the picklist object which contain the notesuiworkspace object. The class contains member functions to set every parameter of the original picklist function. Defaults values are set when instantiating the object. There is two basic function to display the picklist 1. getSingleDocument() which return a simple document and getMultipleDocuments() which give you the notesdocumentcollection. Give a look to the class, it’s easy.

Link to the lss file

First download the .lss file and put everything in a script library. Then you should add the use statement.
The class allows you to customize easily the picklist but it is more convenient than the ugly function from the notesUiworkspace… give it a try and enjoy.

One cool thing is to derivate the class and then create all the picklist you need in a new class, then you’ve got centralized your picklists in a central class which allows to simplify the maintenance cycle of your app.

Greetings.

A remain of the past – the dusty console

After sometimes of laziness, (I’m too much playing with facebook and twitter) I’m back on my blog…

Which one of you is an old enough notes freak to remember the dusty old console which was the bread and butter of the dark age of the domino administration ? at this time to administrate a notes server you only need a strong knowledge of the domino directory and a simple console… old good times !

The old console remains in lotus notes today, and you can call it which a simple macro :

@Command([AdminRemoteConsole]) ;

Of course you need the rights to do it, it could be very useful when you are stuck with a “simple” notes client…

The cCounter class.

* When programming a very long an complex agent it’s very fine to display the agent stats at the end of the agent’s execution. These stats could be a lot of numeric data. It’s a pain to declare and manage all these variables.
* For doing this you need to create a lot of different counters and it’s very boring to manage the init part of these counters, the increment and the display. And what a pain if you want to add a new counter…
* With my solution you will find this very easy to manage and you will add a lot of interesting counters in your next complex agent.
* The idea is to put every counter in a class which will manage for us the boring job.
* This class will init the counter, manage the increment and give us the text.

Here the code :

'  Class counter v1.0
'  By Pierre Koerber

Class cCounter
lCounter List As Long

Public Function incrementCount(sCounterName As String)
If Iselement(lCounter(sCounterName)) = False Then
lCounter(sCounterName) = 1
Else
lCounter(sCounterName) = lCounter(sCounterName) + 1
End If
End Function

Public Function toString() As String
Dim sRes As String
Forall x In lCounter

If sRes = "" Then
sRes = Listtag(x) + "=" + Cstr(x)
Else
sRes = sRes + "," + Listtag(x) + "=" + Cstr(x)
End If
End Forall
toString = sRes
End Function

End Class

'-------------------------------

' calling code, this allows you to manage three counter in a easy and cool way.

'-------------------------------

sub initialize
dim counter as new cCounter()

set doc = dc.getFirstDocument
while not(doc is nothing)
if doc.Subject(0) = "" then
Call counter.incrementCount("Err")
else

call counter.incrementCount("Treated")
end if

Call counter.incrementCount("RcdTreated")
set doc = dc.getNextDocument(doc)
wend

log(counter.toString())

end sub

Install the domino server java console

For me the java console is a lost gem for the notes administrators.

It is a good feature because it allows to administrate all your server from one single point. It will run the console separatly from your notes client, and this is good because the admin client sucks ! it give you more but that’s not the subject of this post.

This article allows you to configure your Windows server to make it run.

First you should modify the start of your server to make it load the domino controller and the java console.

Take “the HKEY_LOCAL_MACHINE\System\CurrentControllSet\Services” key and look for the Lotus Domino key.  In there you will find an entry called ImagePath.  The add to the service’s parameter the -c to load the domino controler and the -jc if you want to load the java console the machine.

domino-server-registry

After that your server should start as in this picture :

domino-server-reg-edit

You could start the console from your notes client directory to have the same on you computer… nice isn’it.

Action to populate a custom user signature…

One big week for “myLife 2.0″

This was a great week for my blog. I’m not a regular blogger (it takes so much times) but this week I was referenced on the famous http://www.codestore.net… it has boosted my visits… that’s pretty cool.

eMail signature, 2 choices

What about the corporate signature. There is a lot of way to do it, since R7 you can customize it and manage it on the notes server… but if you want to allow your users to manage their signature this TIP is for you.

eMail signature, HTML or Text based ?

The next point is to know if you want a fancy and flashy HTML signature with pictures (hey, we’re living in the third millenium !). From my point of view, I prefer a text based signature, it’s simple, it works in all the case… so it’s profesionnal… the HTML is nice but it is impredictable to know how it will be seen on the user device (hey, users aren’t only reading their eMail on their computer…).

One dusty old script…

Going back my archives from the time when I was a full-time admin (one year ago) I found this little gems. So here one dusty old script from my archive… it was one of my first one I wrote when I began to administrate a domino domain.

The purpose of this script is to send a button to the users to let them edit their signature. This script composes a text user signature from the data in the nab (STEP 1, 2, 3). Then the script sends an eMail to the administrator to allow the tracking (STEP4) . Finally it presents the signature  to the user to allow to correct it. (STEP5)

You can put this script in a button (TEST it before and remove the steps you don’t need)

So, I hope it will help you to make your users happier !!!

Greetings

@REM “-STEP1-Parameters—————————–” ;
srv := “yourServerName” ;
db := “names.nsf”;

@REM “-Retrieve the user data in the nab-” ;
Line := “————————————————————————–” ;
Nom := @Name([CN] ; @UserName) ;
eMail := @DbLookup ( “” : “NoCache”;srv:db;”($Users)”;@UserName;”InternetAddress”) ;
fct := @DbLookup ( “” : “NoCache”;srv:db;”($Users)”;@UserName;”????”) ;
tele := @DbLookup ( “” : “NoCache”;srv:db;”($Users)”;@UserName;”Phone”) ;

@REM “-STEP2-ADDRESS LINES ——————————–” ;
Adresse1 := @If(@IsError(fct);”Function : ” ;fct) ;
Adresse2 := “Your company NAME”  ;
Adresse3 := “City number” ;
Adresse4 := “Tel. ++41(0)27.7.661.” + @If(@IsError(tele);”" ;tele) ;
Adresse5 := “Fax. ++41(0)27.7.661.485″ ;
Adresse6 := “EMail    : “  + @If(@IsError(eMail);”";eMail) ;
Adresse7 := “Internet : http://www.yourCompany.com” ;

@REM “-STEP3-Create the signature ——————————–” ;
Signature := @NewLine +  @NewLine + Line + @NewLine + Nom + @NewLine + Adresse1 + @NewLine + @NewLine + Adresse2 + @NewLine + Adresse3 + @NewLine + @NewLine + Adresse4 + @NewLine + Adresse5 + @NewLine +   @NewLine +  Adresse6 + @NewLine + Adresse7 + @NewLine +Line ;

@REM “-Set it to the user profile ——————————–” ;
@SetProfileField(“CalendarProfile” ; “EnableSignature” ; “1″) ;
@SetProfileField(“CalendarProfile” ; “SignatureOption” ; “1″) ;
@SetProfileField(“CalendarProfile” ; “Signature_1″ ; Signature) ;

@REM “-STEP4-Send an eMail to the admin to check follow-up purpose, could be a mailing db ——————————–” ;
@MailSend( “pierre koerber” ; “” ; “” ; “Mise à jour signature ” + @Name([CN] ; @UserName) ; “” ; “”) ;

@REM “-STEP5-Display the dialog to the user, to edit purpose ——————————–” ;
Texte :=”In the next windows, you could check the signature that will be added in your eMails.” + + @Char(13) + @Char(13) + “Cliquez sur l’onglet signature et contrôlez :” + @Char(13) + “1. La fonction” + @Char(13) + “2. Le no de FAX” + @Char(13) + “3. L’adresse eMail” ;
@Prompt([Ok];”Validation” ; Texte) ;
@Command([ToolsRunMacro];”(Preferences)”)

Remove the space in a string…

Last week I was searching a way to suppress spaces in a string. I thought about the trim function… but it doesn’t do the magic.
After several minutes of thinking with the web I found a simple way…
The conclusion is : we become stupid, we can’t think first, we’re going on the web…

Dim x as string
x=”1  2   2 3  4 5″
‘*** Packed x without spaces !
x = replace(x, ” “, “”)

Follow

Get every new post delivered to your Inbox.