Pages

Wednesday, June 30, 2010

Open documents in a traditional form from XPage View Control

Follow the following procedure in order to create links with in the XPage View Control Panel which will help u open up documents associated with the links in traditional notes environment rather than in xpages.

1. Create an XPage
2. Drag and drop a view control on to it and ensure that the view you embedded previews fine
3. Select the view control, go to the all properties section ->data >var . Mark this value as "rowData" case sensitive as illustrated in the following figure.


4. Now select the column where u would like to see the links to open the document in notes client (form - document environment)
5. In the properties pane, select the Data tab and click "computed value", as illustrated in the following figure


6. Now key in the following code in to the scripting section.

if (!rowData.isCategory())
"<a href='notes://serverName/dbPath/0/"+rowData.getUniversalID()+"?OpenDocument'>"
+rowData.getColumnValue("columnName")+"</a>"


*change the bolded values to match ur requirement


7. Now select the View Column tab. In the Column Display Properties, Select Content-type as "HTML" as illustrated in the following figure.
8.Now save and preview the page. You will be able to see your views with links that upon clicking will open the associated documents in the traditional way.

Hope this Helps :)

Wednesday, June 23, 2010

removeAttachment in XPages

The following is a simple function that will consume a document's url and remove a specified attachment from the same on the fly from Xpages.. I have created the same to help a blog reader who was facing issues with the same.



/******************************************************
@Author : Karthikeyan A
@Created: 23-Jun-2010, Qatar
@Purpose : To delete a specific attachment from a document, provided the attachment
                name and the doc url are provided@Type : Function
@Name : removeAttachment
@Param : targDB:NotesDatabase, The database in which the attachment is present
@Param : doc_Url:String, The url of the document that contains the attachment
@Param : fileName:String, The name of the attachment to be deleted
*******************************************************/
function removeAttachment(targDB,doc_Url,fileName) {
//passing parameters by reference
var docUrl:String= doc_Url;
var targetDB:NotesDatabase=targDB;
var attachmentName:String =fileName;


//deducing the document's unid from the document's url
docUrl=@Left(docUrl,"?");
var docUnid=@RightBack(docUrl,"/");


//setting the handle to the document
var docContext:NotesDocument=targetDB.getDocumentByUNID(docUnid);
if (docContext==null) {
viewScope.CodeError="Either the UNID is invalid or the target db does not contain the doc or both";
return;
}


//getting the handle to the concerned attachment
var embObj:NotesEmbeddedObject=docContext.getAttachment(attachmentName);
if (embObj==null) {
viewScope.CodeError="No attachment is found by the name "+ attachmentName;
return;
}

//remove the attachment
embObj.remove()
//save the document so that the changes gets into effect.. other wise no change will be infered
docContext.save(true,false);
}

Hope this helps :)

Monday, June 21, 2010

Simple Lotusscript Logger

This is in analogous to the post found in the following location :

http://ozinisle.blogspot.com/2010/05/xpage-error-handler.html

You may have to create the small database that is mentioned in that post (... will hardly take a minute)

The following is its lotus script equivalent,

Public Class LSLog
    Private session As NotesSession
    Private logDB As NotesDatabase
    Private logDoc As NotesDocument
    Private instantUpdate As Boolean
    Private logHistory As String
    Private isDebug As Boolean
   
    Public Sub new
        isDebug=False
        If Not isDebug Then Exit Sub
        Set session = New NotesSession
        Set logDB=session.GetDatabase("","myXPageLog.nsf")
        Set logDoc=logDB.CreateDocument
        logDoc.Form="log"
        instantUpdate=True
    End Sub
   
    Public Function update (detail As String)
        If Not isDebug Then Exit Function
        logHistory=logHistory & detail & Chr(13)
        If instantUpdate Then
            Call logDoc.ReplaceItemValue("log",logHistory)
            Call logDoc.Save(True,False)
        End If
    End Function
   
    Public Function close
        If Not isDebug Then Exit Function
        Call logDoc.ReplaceItemValue("log",logHistory)
        Call logDoc.Save(True,False)
    End Function
   
    Public Function kickInsert(anyValue As Variant)
        If Not isDebug Then Exit Function
        Call logDoc.ReplaceItemValue("log",anyValue)
        Call logDoc.Save(True,False)   
    End Function
   
End Class

Friday, June 18, 2010

Handling "Error loading USE or USELSX module"

As far as I understand the error message saying "Error loading USE or USELSX module" occurs in one typical scenario which is as follows.

You define a function. Put that in a script library and call the same on a event, say a button click on a form.
Later for some reason say you have been updating the function in the script library pretty often.
So the invoking code would be of a comparitively older version when compared with the one in the script library. This is one scenario where this error occurs...

There are other scenarios where this would occur. For example delare a constant in the form globals, say

 CONST MYCONST="my value"

Now create a script library. Put the above mentioned code in the declarations section of the same, save the same and include that on the form which we created a before.

Now since the same constant has been defined in multiple places, you will get this error.

Solution

In the designer, select the Application (Database) in the outline (Application Outline).
Now click tools in the top margin.
Click "Recompile All Lotusscript"

As the name implies, all the lotusscript code present in the database will get recompiled.
It will show a progress info and after completion it will show the design elements where duplications or errors exist...

So u can rectify them.

Hope this helps :)

Wednesday, June 16, 2010

View XPage Source Code on browser

This was an accidental discovery to me.

Key in the URL of your xpage on the browser followed by a plus sign (+)

Now hit enter and there you go, you will be able to see the XPage source code on the browser

For example your url must follow the following format
     http: //server/dbpath/xpageName.xsp+

Illustration: refer to the following figure


Note: This works only with IE.In case of Firefox and Chrome, it results in the download of a file with an extension "xsp"

Edit: This shall be helpful for development purpose. You will be able view the source code only if you have Manager or designer access to the database that you have in your own server or local. Hence this would fail for public sites like ideajam.net etc... This simply wont work

Monday, June 14, 2010

Toggle display of an html element

Following is a block of code that shall help one toggle display of a html eelement

/**************************************************************************
@Author : Karthikeyan A
@Created: 27-May-2010
@Purpose : To toggle an element's display property
@Type : Function
@Name : toggleDisplay
@Param : elementID, ID of the element whose display property needs to be toggled
**************************************************************************/

function toggleDisplay(elementID) {
var element;
// get the element referenced by the parameter elementID
if (typeof elementID === "string") {
element = document.getElementById(elementID);
} else {
element = elementID
}
// if an element with such an id is not found then through an error
if ((typeof element == 'undefined') || (element == null)) {
throw new Error(
'An element with id "' + elementID + '" is found when executing function toggleDisplay(elementID)');
}
// get the display style of the element
var dispStyle = element.style.display;
// if its none then display the element or hide the same
if (dispStyle == 'none') {
element.style.display = 'block';
// for ie version prior to and including 7
var ie = document.all;
if (ie) {
// for ie5
if (document.layers)
element.visibility = "show";
else
element.style.visibility = "visible";
}
} else {
element.style.display = 'none';
}
}

Saturday, June 12, 2010

Some valid conditions that always returns true in Javascript

Following are illustrations of definte conditions which will always return true in javascript...

if(1) alert("block 1 executed");

if(1.0) alert("block 1.0 executed");

if ( true) alert("block true executed");

var obj=document.body;
if(obj) alert("block object executed");


Click the button to test these conditions:

Thursday, June 10, 2010

deleteCollectionWithDescendents in Lotusscript

Function deleteCollectionWithDescendents(inputDocCol As NotesDocumentCollection ) As Boolean
'******************************************************************
'@Created : 10-Jun-2010
'@Author : Karthikeyan A
'@Purpose: To delete documents in a collection along with their descendents
'@Type : Function
'@Name : deleteCollectionWithDesendents
'@Param : inputDocCol - the collection of documents which must be deleted along with descendents
'@Return : Boolean- true if operation suceeds and false other wise
'******************************************************************
'mark the flow of control getting inside the current function
deleteCollectionWithDescendents=False

'declare all variables and objects necessary for further manipulation
Dim resDocCol As NotesDocumentCollection
Dim doc As NotesDocument
Dim tempDoc As NotesDocument

'handle errors in case of abrupt termination
On Error Goto errHandler

'if there are no documents found in the collection then exit function
If inputDocCol.Count=0 Then Exit Function
'get the first document in the collection
Set doc=inputDocCol.GetFirstDocument()
'loop and delete the document along with its descendents untill no more selected documents exist
While Not doc Is Nothing
'get the collection of the responses of the current doc of interest
Set resDocCol=doc.Responses
'reinitiate the process with this collection as the input - recursion
Call deleteCollectionWithDescendents(resDocCol)
'once all the descendents are removed, remove the parent (current document of interest)
Set tempDoc=doc
'set the handle for the next document in the collection
Set doc=inputDocCol.GetNextDocument(doc)
Call tempDoc.Remove(True)
Wend

'mark the flow of control moving out of the current function
deleteCollectionWithDescendents=True
Exit Function
'inform the user about the error that resulted in abrupt termination
errHandler:
Msgbox "Error: ***" & Error & "*** encountered on line *** " & Cstr(Erl) & " *** with error number *** " _
& Cstr(Err) & " *** in function deleteCollectionWithDescendents"
End Function

Wednesday, June 9, 2010

"pt" and "px" - are different units of measurement in CSS

The unit "pt" stands for Points and "px" stands for pixels.

When I happened to position a particular element on the XPage beneath a button on the fly, when I click the same, I happened to see all weard behaviours...

All of my javascript alerts where correct values but still the element which I repositioned was relocated to a unexpected location on the screen.

This was because of the difference between these units...

The position attribute that I got from my button was on points (pt) and I actually was assiging them back to the dynamic element on pixels (px) ... hence there was a mismatch and this occured with XPages on Notes Client..

the relation between pt and px is as follows,

pt = 0.75px

Note : Its seems like your style sheets must include pt if and only if its a print style sheet ...
em,mm,px and now pt... I dont know how many else are there...  Got to find them:)

Get Html Element Position in a web page

In order to find the position of an element on a webpage, Pass the element handle as parameter to the following function on the page. This function works with XPages on Notes Client as well.

function getElementPosition( htmlElement ) {
    var xPos = 0;
    var yPos = 0;
    
    while( htmlElement && !isNaN( htmlElement.offsetLeft ) && !isNaN( htmlElement.offsetTop ) ) {
        xPos += htmlElement.offsetLeft - htmlElement.scrollLeft;
        yPos += htmlElement.offsetTop - htmlElement.scrollTop;
        htmlElement = htmlElement.parentNode;
    }
    
    return { top: yPos, left: xPos };
}

Illustration,

Put the following code on a button which includes the above function and click it.

var myElement=document.getElementById(thisEvent.target.id);
try{
var coorde=getElementPosition( myElement );
var x = coorde.left;

var y = coorde.top;
alert(x+" "+y);
} catch (error) {
alert(error.message);
}

Hope that helps :)

Monday, June 7, 2010

NotesURL of design elements and documents

We can easily identify the web url of a design element.

we can obtain it by simply previewing the same on the browser.

And it will of the sort,
   http://servername/databasepath/designelement?open....

Where as we would not be familiar of how to create a or find a notesurl of a design element.
Its simple, replace the "http" found in above mentioned format by "notes". Yes it is that simple.
The notes url of a form named testForm would be,

notes://servername/databasepath/testForm?openform...

This will open up the form on the notes client even when attempted from the web.

Incase of xpages, it would open up the database's default view or frameset when attempted.

In order to find the notes url of the documents following would be a work around.
Simply copy the link of a document and paste the same on a word document and move over it...
you will be able to see the Notes Url of the same.

Hope this helps :)

@DBLookup from a different database present in a different server in XPages

Following is a illustration of how to perform a @DBLookup when the source of data resides in an entirely different database and server.

var dbName=Server-Name+"!!"+Database-Path
 result= @DbLookup(dbName,viewName,lookupKey, {lookupField or column no})
 
This is a small trick which most of us would often forget and wont care about....
It can turn into a real head ache though..... :)
 
Hope this helps.

Thursday, June 3, 2010

#9: Issue in XPage: Xpage refresh results in creation of duplicate documents

I am currently facing an issue in Xpages which is haunting me....

Initially I had issues with Required fields getting validated in every server refresh. I fortunately stumbled upon Tommy Valand's blog and found beautiful solutions to many issues. When I used the code and fixed the same.. this monster arrived at my door step...

A brief description would be,

1.Open an Xpage which is bound to some data source and has a submit button which saves the underlying document.


2. Save the XPage by clicking the submit button and cross check with the view that displays the underlying document in notes

3.Now press F5 on key board. You will get a prompt saying the following message,

The page you are trying to view contains POSTDATA. If you resebd the data,
any action the form carried out(such as a search or online purchase) will be
repeated. To resend the data, click OK. Otherwise, click Cancel.


4.Clicking Ok on this prompt will create a duplicate document

This is one issue that is haunting me in my current project

Link styles - Pseudo Classes

There are times when styles like a:active fail. This is because , the styles assume a pseudo order and works according to the hierarchy in which they are declared or defined in the style sheet.

For example a:active shall fail when the pseudo classes for the links are defined in the following order

:link

:visited
:focus
:active {style-active}

:hover {style - hover}

hover shall over ride active....

so while writing styles plan accordingly ,

:)

Add multiple attachments to a rich text field

The following is a simple function that takes in an array of filenames and attachs them to the mentioned field in the mentioned document,,,,

Function addFilesToRichTextField(contextDoc As NotesDocument,rtFieldName As String, fileNames As Variant) As Boolean
'****************************************************************************************************************************
 '@Author    :    Karthikeyan A
'@Name    :    addFilesToRichTextField
'@Purpose:    To attach multiple attachments to a particular document in a particular richtext field 'with the information on the source path of the files
'@Param    :    contextDoc - the document that contains the richtext field
'@Param    :    rtFieldName - The name of the rich text field that should hold the attachments
'@Param    :    fileNames - An array of file names that are to be uploaded to the document's rtfield
'@Return    :    Boolean : true if operation succeeds and false otherwise
'****************************************************************************************************************************
   
    'mark the flow of control getting inside the current function
    addFilesToRichTextField=False   
   
    'declare all variables and objects necessary for further manipulation
    Dim rtItem As NotesRichTextItem
   
    'handle errors in case of abrupt termination
    On Error Goto errHandler
   
    'validate parameters
    'if the context document is nothing then inform the same to the user and exit
    If contextDoc Is Nothing Then
        Msgbox "The handle to the context document to which the attachments are to be added is not set in function ""addFilesToRichTextField""",,"Error in ""addFilesToRichTextField"""
        Exit Function
    End If
   
    'if there are no file names provided then exit function
    If Isempty(fileNames) Then
        'no problem skip execution
        Exit Function
    End If
   
    'if the rich text field name is not provided throw an error
    If Trim(rtFieldName)="" Then
        Error 1001,"Invalid input param - ""fileNames is Empty"" in function ""addFilesToRichTextField"""
    End If
   
    'set the handle for the rich text item associated with the field name provided
    Set rtItem=contextDoc.GetFirstItem(rtFieldName)
   
    'loop through all the filenames and embed them into the rich text field
    Forall fileName In fileNames
        If Trim(Cstr(fileName)) <> "" Then
            Call rtItem.EmbedObject(EMBED_ATTACHMENT,"",Cstr(fileName))
        End If
    End Forall
   
    'update richtext item
    Call rtItem.Update()
   
    'save the current document so that the changes get updated to the document permanently
    Call contextDoc.Save(True,False)
   
    'mark the flow of control moving out of the current function
    addFilesToRichTextField=True
    Exit Function
    'inform the user about the error that resulted in abrupt termination
errHandler:
    Msgbox "Error: ***" & Error & "*** occured online ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) &"***",,"Error in function""addFilesToRichTextField"""
    Exit Function   
End Function



Hope this helps.... :)

Creating Frameset Using Forms Or Pages In Lotus Notes

Following is a simple procedure that will help you create a frameset using a form or a page design element in lotus notes.

1.Create a Notes Database and ensure that you have a user by the name Anonymous with Editor or higher access, if you create the database in local

2.Create a form design element with name "myForm.html"

3.In the "Defaults" tab of the form property box enable the following option

On Web Access -> Content Type -> HTML

4. Now copy paste the following code into the form
<frameset cols="20%,80%">
<frame src="">
<frame src="http://www.ozinisle.blogspot.com&quot:>
</frameset>


5. Now preview your form on the browser using a url similar to the following,

http://server/dbpath/myForm.html?readForm

Tuesday, June 1, 2010

My BookMarks

IBM WebSphere Portal
1.Developing portlets using Eclipse and WebSphere Portlet Factory
http://www.ibm.com/developerworks/websphere/tutorials/0606_coqueiro/index.html

2.IBM WebSphere Portlet Factory Tutorial
http://public.dhe.ibm.com/software/dw/wes/pdf/wpfsamps/DominoCollaborationBuilders.pdf

3.IBM WebSphere Portlet Factory Designer
http://publib.boulder.ibm.com/infocenter/wpfhelp/v6r0m2/index.jsp?topic=/com.bowstreet.designer.doc/tutorials/Custom_Builder_Introductory_Tutorial.htm

4.WebSphere Portlet Factory wiki
http://www-10.lotus.com/ldd/pfwiki.nsf

5.WebSphere Portlet Factory Solution Overview.ppt
http://www.ibm.com/developerworks/forums/servlet/JiveServlet/download/888-251878-14218258-336690/WebSphere%20Portlet%20Factory%20Solution%20Overview.ppt

6.Tutorial – Creating a Simple Portlet
http://publib.boulder.ibm.com/infocenter/wpfhelp/v6r1m5/index.jsp?topic=/com.bowstreet.designer.doc/tutorials/TutorialBasics_Simple_Portlet.htm

Lotus Notes

1.How to get your Notes Webmail working in Firefox 4
http://dominogavin.blogspot.com/2011/03/how-to-get-your-notes-webmail-working_968.html

XPages:

1. Vedio demonstration on Display Error Control in XPages
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/XPages-Data-validation.htm

2. Developing charts in XPage - that's awesome and cool
http://lsoy.posterous.com/xpages-charting-magic

3. Creating a view picklist in XPages
http://www.youatnotes.de/web/youatnotes/blog2.nsf/dx/xpages-display-a-panel-as-nice-dojodijit-dialog-on-page-load.htm

4. Working with Java and JSF in XPages - A whole new insight to XPages
http://www.mindoo.com/web/blog.nsf/archive?openview&title=XPages&type=cat&cat=XPages

Lotus Script:

1.Code project that would help you send html conents in browser view through mail (native notes)
http://www.openntf.org/Projects/codebin/codebin.nsf/0/4322A3203262705188256D5E0034329D

2. Custom lotusscript classes
http://dev.kanngard.net/dev/home.nsf/ArticlesByCategory?OpenView&RestrictToCategory=LotusScript&Count=1000

3. Moorthi Daniel's blog - contains a lot of use full functions. Following is a gest

i, copy richtextitem from one document to another document
ii, how to check tich text field is empty or not
iii, how to get lotus notes temporary directory
iv, getalldocumentsbykey - too many keys error
v, unzip a file using zip
vi, browser for folder - force user to select folder using lotus script
and more

http://www.moorthidaniel.com


Online Tools
1. HTML Encoder & Decoder (link to decoder is available on the same site)
http://www.opinionatedgeek.com/dotnet/tools/htmlencode/Encode.aspx

2. An online resource where you can create your our animated "Loading..." sort of images
http://ajaxload.info/

UI Themes


1. Blue Black combination
http://wp-themes.com/wp-content/themes/annexation/screenshot.png

Symphony



4. This link is for both Symphony document & Symphony Spreadsheet.