Sunday, September 20, 2009

Showing alternate coloured rows on Web

There has been quite a few solutions to produce alternate row colors for a Web view. They all involve writing cluttered HTML in the column headings, treating view contents as HTML, or using agents, etc. But the following solution is purely a javascript function and has nothing to do with Domino view design. Part of this idea was derived from a posting in the notes.net site.



Step 1.) Create a view with few columns(Let it be uncategorized initially).

Step 2.) Embed the view in a form(Display as HTML).

Step 3.) Put the following code in the Onload event of the form.(Or have it as a function in the JS Header and call it in the OnLoad event).


var tableElements = document.body.all.tags("table");
var table = tableElements[tableElements.length-1];
var headlength=rowlength="";
heads = table.getElementsByTagName("th") ;
headlength=heads.length;

// If the view is categorized , use this line, else comment it
//headlength=headlength-1;

for( i = 0; i <headlength; i++)
heads[i].bgColor = '#D2D2D2';

rows = table.getElementsByTagName("tr") ;
for( i = 0; i < rows.length; i++)
{
if(i % 2)
{
// If the view is not categorized , use this line
celllength=rows[i].cells.length;
// If the view is categorized , use this line
//celllength=rows[i].cells.length-1;

for (var c = 0; c < celllength; c++)
rows[i].cells[c].bgColor = '#F4F4F4';
}
else
rows[i].bgColor='';
}

(The code is self explanatory. It gets the table element, changes the background color of the cells. The above code works fine for an uncategorized view.)

Step 4: For a categorized (single or many), uncomment the following lines,

//headlength=headlength-1;
//celllength=rows[i].cells.length-1;

and comment the following line.
//celllength=rows[i].cells.length;

This should work well for a categorized view.

Step 5 : To provide alternate column color effect, modify the for loop given below,

for (var c = 0; c < celllength; c++)
rows[i].cells[c].bgColor = '#F4F4F4';

to,

for (var c = 0; c < celllength; c++)
if (c % 2)
rows[i].cells[c].bgColor = '#F4F4F4';



The above javascript function is fully customizable like,
table.cellspacing='2'
table.cellpadding='2'
and the bgcolor values etc.

Creating Notes Documents from Excel Sheet in lotusscript


Sub Initialize
Dim lspath,lsextn As String
Dim gosession As New NotesSession
Set godb=gosession.CurrentDatabase
Set godoc=New notesDocument(godb)

'Enter the Path and the XL file that has to be Imported into th
database..like the one is shown below

lspath=Inputbox$("Enter the Excel file path for importing into
the Notes Database")

lsxlFilename=lspath

'Create an Excel sheet object

Set gvExcel=CreateObject("Excel.Application")
gvExcel.visible=False

Messagebox ("Opening Excel sheet File eneterd in Input box
previously ...")
gvExcel.Workbooks.Open lsxlFilename
Set gvxlWorkbook=gvExcel.ActiveWorkbook
Set gvxlsheet=gvxlWorkbook.Activesheet

'Start to move through the Excel file and start pulling data
from there
lsrow=0
lswritten=0

'Start Importing into the Notes Database
Print "Start impoting from Excel sheet"

Do While True

With gvxlsheet
lsrow=lsrow+1

'Create a new Notes document

Set godoc=godb.CreateDocument
godoc.Form="TestForm"
godoc.Name=.Cells(lsrow,1).Value
godoc.Division=.Cells(lsrow,2).Value
godoc.Manager=.Cells(lsrow,3).Value

'Save the Notes document
Call godoc.Save(True,True)

lswritten=lswritten+1
If godoc.Name(0)="" Then
End
End If
End With

Loop
Set godoc=Nothing
gvExcel.quit

Goto CleanUp

CleanUp:
Exit Sub

ErrorHandler:
Msgbox "An error has occurred in the agImport at line no. " &
Erl() & " and the error is " & Str$(Err) & " " & Error$
Resume CleanUp

End Sub

Return to previous page after submit in javascript

Place in a $$Return field on a form.



More clear picture


Creating Word Document from Notes

Here is the code to export to word:

Function exportDataToWord(lsCITRDescTitle As String, lsFileName As String, loUDoc As NotesDocument) As Integer
'%REM
On Error Goto ErrorHandlerFunc

Dim wordObj, wdocs, wRange As Variant
Set wordObj = CreateObject("Word.Application")
Set wdocs = wordObj.Documents.Add(lsFileName)
wdocs.Activate
'wdocs.

Set wRange = wdocs.Bookmarks("wCITR_CreationDt").Range
Dim dateTime As New NotesDateTime(Cstr(loUDoc.CITR_CreationDt(0)))
lsEffDt$ = dateTime.DateOnly
wRange.InsertBefore lsEffDt$

Set wRange = wdocs.Bookmarks("wCITR_SNDANo").Range
wRange.InsertBefore Cstr(loUDoc.CITR_SNDANo(0))

Set wRange = wdocs.Bookmarks("wCITR_Number").Range
wRange.InsertBefore Cstr(loUDoc.CITR_Number(0))

lvConxDiscInfo = Evaluate(|@Implode(CITR_ConxDisc; @Char(13))|, loUDoc)
lsConxDiscInfo$ = Trim$(Cstr(lvConxDiscInfo(0)))
Set wRange = wdocs.Bookmarks("wCITR_ConxDisc").Range
wRange.InsertBefore lsConxDiscInfo$

lvOtherDiscInfo = Evaluate(|@Implode(CITR_OtherDisc; @Char(13))|, loUDoc)
lsOtherDiscInfo$ = Trim$(Cstr(lvOtherDiscInfo(0)))
Set wRange = wdocs.Bookmarks("wCITR_OtherDisc").Range
wRange.InsertBefore lsOtherDiscInfo$

Dim z As Integer
Dim lvCITRPurposes As Variant
Dim lsSetOtherReason As String
If (lsCITRDescTitle = "First Version") Then
Set wRange = wdocs.Bookmarks("wCITR_PurposeOfDisc").Range
wRange.InsertBefore Cstr(loUDoc.CITR_PurposeOfDisc(0))

lvContainOther = Evaluate(|@Contains(CITR_PurposeOfDisc; "Other")|, loUDoc)
lsContainOther$ = Trim(Cstr(lvContainOther(0)))
If (lsContainOther$ = "True" Or lsContainOther$ = "true" Or lsContainOther$ = "1") Then
lvCITR_OtherReasons = Evaluate(|@Implode(CITR_OtherReasons; @Char(13))|, loUDoc)
lsCITR_OtherReasons$ = Trim$(Cstr(lvCITR_OtherReasons(0)))
Set wRange = wdocs.Bookmarks("wCITR_OtherReasons").Range
wRange.InsertBefore lsCITR_OtherReasons$
End If
Else
lsCap1$ = Trim(Cstr(wDocs.chkA.Caption))
lsCap2$ = Trim(Cstr(wDocs.chkB.Caption))
lsCap3$ = Trim(Cstr(wDocs.chkC.Caption))
lsCap4$ = Trim(Cstr(wDocs.chkD.Caption))
lsCap5$ = Trim(Cstr(wDocs.chkE.Caption))
lvCITRPurposes = loUdoc.GetItemValue("CITR_PurposeOfDisc")
For z = 0 To Ubound(lvCITRPurposes)

If (Trim(Cstr(lvCITRPurposes(z))) = lsCap1$) Then
wDocs.chkA.value = True
Elseif (Trim(Cstr(lvCITRPurposes(z))) = lsCap2$) Then
wDocs.chkB.value = True
Elseif (Trim(Cstr(lvCITRPurposes(z))) = lsCap3$) Then
wDocs.chkC.value = True
Elseif (Trim(Cstr(lvCITRPurposes(z))) = lsCap4$) Then
wDocs.chkD.value = True
Elseif (Trim(Cstr(lvCITRPurposes(z))) = lsCap5$) Then
wDocs.chkE.value = True
End If

If (Trim(Cstr(lvCITRPurposes(z))) = "Other") Then
lsSetOtherReason = "1"
End If

Next

If (lsSetOtherReason = "1") Then
lvCITR_OtherReasons = Evaluate(|@Implode(CITR_OtherReasons; @Char(13))|, loUDoc)
lsCITR_OtherReasons$ = Trim$(Cstr(lvCITR_OtherReasons(0)))
wdocs.txtbxA.value = lsCITR_OtherReasons$
End If
End If
lvCITR_Address = Evaluate(|@Implode(CITR_Address; @Char(13))|, loUDoc)
lsCITR_Address$ = Trim$(Cstr(lvCITR_Address(0)))
Set wRange = wdocs.Bookmarks("wCITR_Address").Range
wRange.InsertBefore lsCITR_Address$

Set wRange = wdocs.Bookmarks("wCITR_Address1").Range
wRange.InsertBefore Cstr(loUDoc.CITR_Address1(0))

Set wRange = wdocs.Bookmarks("wCITR_OtherCompName").Range
wRange.InsertBefore Cstr(loUDoc.CITR_OtherCompName(0))

Set wRange = wdocs.Bookmarks("wCITR_City").Range
wRange.InsertBefore Cstr(loUDoc.CITR_City(0))

Set wRange = wdocs.Bookmarks("wCITR_StateCountry").Range
wRange.InsertBefore Cstr(loUDoc.CITR_StateCountry(0))

Set wRange = wdocs.Bookmarks("wCITR_Zip").Range
wRange.InsertBefore Cstr(loUDoc.CITR_Zip(0))

Set wRange = wdocs.Bookmarks("wCITR_Representor").Range
wRange.InsertBefore Cstr(loUDoc.CITR_Representor(0))

Set wRange = wdocs.Bookmarks("wCITR_Signer").Range
wRange.InsertBefore Cstr(loUDoc.CITR_Signer(0))

Set wRange = wdocs.Bookmarks("wCITR_Desig").Range
wRange.InsertBefore Cstr(loUDoc.CITR_Desig(0))

Set wRange = wdocs.Bookmarks("wCITR_Title").Range
wRange.InsertBefore Cstr(loUDoc.CITR_Title(0))

wdocs.SaveAs lsFileName$
wdocs.Close
wordObj.Application.Quit

lsPathOfWord$ = "C:\Program Files\Microsoft Office\Office\WINWORD.EXE " & Cstr(lsFileName)
taskId% = Shell(lsPathOfWord$, 1)

exportDataToWord = True

Exit Function

ErrorHandlerFunc:
Print "Error Msg : " & Error$() & " at line no. of Function : " & Erl()
Resume Next
'%END REM
End Function

Thursday, September 10, 2009

Set the value of combobox in javascript, set the value of html select value in javascript

Problem: Set the value of a combobox in javascript
Solution: For combobox give the values and names.
for ex:


Screenshot:
Javascript code to set the value of combobox:
document.forms[0].Combo.value="Test2";
i put the above code in Onload of the body. so by default the combo box value is "Test2".
The above code should work 99%. If the above javascript code is not working then use this:
for (var i=0; i (lessthan symbol here) document.forms[0].Combo.length; i++) {
if (document.forms[0].Combo[i].value == "Test2") {
document.forms[0].Combo[i].selected = true;
}
}




Wednesday, September 9, 2009

Refer a field value in iframe from parent window

Hi today i came across to read a field value of iframe from a main parent window.

Here is the javascript code:

var temp = document.getElementById('iframeid').document.getElementById('fieldID').value;

Its so simple... Right?

Tuesday, September 8, 2009

Check current users role is [Admin] in lotusscript

Today i came across to check the current user's role is [Admin] or not in Lotusscript.


Here is the code: LotusScript:

Sub Initialize
Dim session As New notessession
Dim db As NotesDatabase
Dim roles As Variant

roles = Evaluate("@UserRoles = ""[Admin]""")
Msgbox Cstr(roles(0)) ' if the message box shows 1 then the current user has Admin role.
End Sub

Monday, September 7, 2009

Agent to Export to PDF in Lotus Notes

A JAVA Agent which exports the values to a PDF file.

After you run the agent please check C drive for the PDF File.

Here is the JAVA code to export to PDF in Lotus Script:

import lotus.domino.*;
import java.io.FileOutputStream;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Chapter;
import com.lowagie.text.Font;
import com.lowagie.text.List;
import com.lowagie.text.Table;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;

public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
//create document's object
Document document = new Document();
try {
//create a document
PdfWriter.getInstance(document, new FileOutputStream("c:\\CreatePDFInlotus.pdf"));
//open doc for r/w
document.open();
//add text
document.add(new Paragraph ("Create PDF in Lotus "));
document.add(new Paragraph ("Create PDF in Lotus "));

//if error
} catch (DocumentException de) {
System.err.println(de.getMessage());
}

document.close();

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


Agent to customize Dialogbox to take the inputs from the user



Create a form with the name "DlgPreview"

Customize the form "DlgPreview" as shown below


Click on Submit and write the below lotusscript code:

Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesuiDocument
Set uidoc = ws.CurrentDocument
Call ws.RefreshParentNote( )
Call uidoc.Close
End Sub

Cancel Button Code:

Formula Language: @Command([FileCloseWindow])

Write an agent to trigger the workspace dialogbox.

Agent Code : LotusScript :

Sub Initialize
Dim ws As New NotesUIWorkspace
Dim s As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDatabase
Dim dlgDoc As NotesDocument
Set s = New notessession
Set db = s.CurrentDatabase
Set dlgDoc = db.CreateDocument ()
If ws.DialogBox("DlgPreview",True,True,True,False,False,False,"Preview Dialog Box",dlgDoc,True,True) Then
Msgbox DlgDoc.DlgField(0)
End If
End Sub

After you run the agent it will display the below dialogbox to enter the value


Ajax function in lotus domino to display a html view in a div innerHTML

The below function is developed in ajax. Paste the following code in the JSHeader of the form.

Create a div with the ID as "Mainbody" to place a web view.

Onload call the processAjax() function.


function processAjax() {

url=dbPath + "Viewname?openview"
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv;
try {
req.open("GET", url, true);
} catch (e) {
alert("Problem : " + e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
var oldchild = document.getElementById("child");
if(oldchild!=null)
{
//document.forms.getElementById("Mainbody").removeChild(oldchild);
document.getElementById("Mainbody").removeChild(oldchild);
}
//-------------------------------------------------------------------
//Create a new div
var wrappingElement = document.createElement('div');
wrappingElement.setAttribute('id',"child");
//Insert response text into new div
wrappingElement.innerHTML = req.responseText;
if(req.responseText.indexOf("No documents found") > 0){
wrappingElement.innerHTML="

Your Message Hear";
//attendee.appendChild(wrappingElement12);
}
//Append new div into mainbody
Mainbody.appendChild(wrappingElement);
setTimeout('processAjax()',10000);
} else {
// alert("Problem: " + req.statusText);
alert("Problem: Server Down1");
}

}
}

Search This Blog