Friday, March 25, 2011

Lotus Script Function to extract all attachements from a Notes Document

Function ExtractFiles (doc As NotesDocument , filePath As String , extract As Boolean) As String
'handle errors in case of abrupt termination
    On Error Goto errorHandler
    'declare all the objects and variables necessary for further manipulation
    Dim rtitem As NotesRichTextItem
    Dim allFileName As String
    Dim attname As String
    Dim path As String
    Dim dirCreated As Boolean
    Dim tempDoc As NotesDocument
    Dim session As New NotesSession
    Set tempDoc  = New NotesDocument(session.CurrentDatabase)
    Call doc.CopyAllItems(tempDoc)
    Call tempDoc.Save(True,False)
    allFileName =""
    dirCreated = False
    Set rtitem = tempDoc.GetFirstItem( "Body")
    'Mantis Issue: 7106 Type Mismatch Error Logged in LNCNSFlog.txt File During Export of Message
    'the following check will verify whether the document has en embedded object
    If ( tempDoc.HasEmbedded ) Then  ' code added by Rajesh Kumar
        While Not rtitem Is Nothing
            Forall eo In rtitem.EmbeddedObjects
                If (eo.Type = EMBED_ATTACHMENT) Then
                    ' If Name and Source are different, Name is a random name assigned by Domino...
                    If eo.Name <> eo.Source Then
                          ' take advantage of the random Name & add extension of the Source...
                        Call LogWrite ("ExtractFileNames - --Name = " + eo.Name + " Source = " + eo.source)
                        allFileName = allFileName + "~~##~~" + eo.source + "||" + eo.Name
                        attname = eo.source + "-~~##~~-" + eo.Name
                          ' No random name was assigned, so it is safe to use Source...
                        allFileName = allFileName + "~~##~~" + eo.source
                        attname = eo.source
                        Call LogWrite ("ExtractFileNames - Extracting ------" + attname)
                        Call LogWrite ("ExtractFileNames - --Source Only= " + eo.Source)
                    End If
                    If (extract) Then
                    'if the directory is created then
                        If (Not dirCreated ) Then
                            path = filePath + Cstr(doc.NoteID)
                            Call LogWrite ("ExtractFileNames - The path is Extract File Names : "+ path)
                        'create a directory
                            Mkdir ( path )
                        'set the value to true
                            dirCreated = True
                        End If
                        Call LogWrite ("ExtractFileNames - Extracting to path : " + path + "\" + attname)
                        Call eo.ExtractFile( path + "\" + attname)
                    End If
                End If
            End Forall
        'remove the current attachment
            Call rtitem.Remove
        'get the handle to the next document which is the first document ,since the previous doc is removed
            Set rtitem = tempDoc.GetFirstItem( "Body")
          ' code added by Rajesh Kumar
        Call LogWrite ("ExtractFileNames - No Attachment found in the Document")
    End If
    ExtractFiles = allFileName
    Call tempDoc.Remove ( True)
    Call LogWrite ("ExtractFileNames - Exiting the function")
    Exit Function
'log the error that resulted in abrupt termination       
    Call LogWrite ("ExtractFileNames - Exiting the function Got error  for doc :" & Cstr(doc.UniversalID) & "   " & Error$ & " on line " & Cstr(Erl))
    ExtractFiles = allFileName
    If Not tempDoc Is  Nothing Then
        Call tempDoc.Remove ( True)
    End If
    Exit Function
End Function

Thursday, March 24, 2011

Implementing JQuery in XPages

In an attempt to implement jQuery in xpages, I just wanted to know if XPages work with jQuery. And I understood that it is possible and the following method helped me make it work

First, include the following script library to your XPage

Then try using some jquery function on it and see it working. The following is an example that I got from w3schools,


<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>

Then preview your page and you will be able to see it work

Hope this helps :)

Wednesday, March 23, 2011

Crash a Domino Server - an other SSJS did it

In addtion to what I have found previously -, I happened to stumble upon an other code fragment that did it. I mean crashing my domino server.

This time its a more serious one to be aware of. Because the following line of code works perfectly until it breaks. So be care full.


where, viewHandle is a NotesView object.

Hope this helps :)

Wednesday, March 16, 2011

@DbColumn - An other way in SSJS

In addition to my recent adventure on crashing a domino server, the following work around helped me fix the issue and it seems to be an elagant way to get the column values from a view column

var viewHandle:NotesView=database.getView(viewName)
return viewHandle.getColumnValues(colNumber-1)

Crash a Domino Server - oops SSJS did it

In an attempt to simulate @DbColumn using SSJS, i used a few lines of code which included the following,


To my astonishment, I found that my domino server had crashed. Yes the server it self had crashed every time it read this code fragment.

I have coded a few lines in the past that crashed Lotus notes client/designer, but never had the opportunity to crash a server. And now it took me XPages to do it :)

Looking for a work around :(

Monday, March 14, 2011

Execute Client Scripts in the After Page Load event of XPage

 In order to execute client side scripts in the after page load events of an XPage, one must use dojo to accomplish it. I think I know an other way to do this, but the one posted below seems simple and effective to me. All you got to do is add the following to your XPage and test it for your self


Hope this helps :)

Wednesday, March 9, 2011

Triggering Client script from server side : Xpages

Triggering client script from server side on XPages saves developers in many scenarios.
I missed them so badly until I came to know about the "xp:onComplete" tag.

Associate this property to the event handler of any of the controls with partial refresh enabled and voila you are ready to go.

The following is a simple example on getting the property to work in xpages.

Ensure that the control does not have full update enabled cos, this method would work only when partial refresh is enabled

Handling "java.lang.OutOfMemoryError" - notes.ini Keyword: JavaMaxHeapSize

Syntax: JavaMaxHeapSize=number of bytes

Example: JavaMaxHeapSize=67108864

Default value: 67108864 (64mb)

Specifies the maximum--not initial--size the Java heap can reach. The Java Virtual Machine (JVM) starts out at 16MB of heap space and most of it is uncommitted. If the JVM needs more heap than it currently has, it will expand the heap in increments but will not exceed the maximum. Exceptions such as "java.lang.OutOfMemoryError" indicate that a heap has reached its maximum size. You can specify the number of bytes directly or use the suffix "MB" to indicate megabytes, for example, specifying "64MB" is the same as specifying "67108864."

Resource obtained from :
Hope this helps :)

Empty Contents of an IFrame - Javascript

Following is one effective way that can help one to empty the contents of an iFrame.


Following are a few other methods that might work,

window.frames[['iFrameID'].location.href=" ";


hope this helps :)

Tuesday, March 1, 2011

Accessing parent from an iFrame

Accessing a the parent page which contains an iframe from with in the iFrame is as follows,

var parentDOMDoc=parent.document

again, access restrictions are applicable here i.e if the IFrame's document are not in the same domain as the parent frame, then you may be denied access to it's contents due to security features of most browsers.

Accessing iframe contents using javascript

The following is a way to access the contents of an IFrame.

var ifrm = document.frames["myIFrame"].document.forms[0]

This should return the form element associated with the iframe. In most cases where the above code fails try using window.frames instead of document.frames and that would work.

On top of this if the IFrame's document is not in the same domain as the parent frame, then you may be denied access to it's contents due to security features of most browsers.