Friday, January 27, 2012

How to create a document link in Browser (iNote)

I opened my mail box in browser not in notes.

I wanted to create a lotus notes document link in my new mail.

I copied my document as a document link. And I pasted it into my composed mail.

But the pasted content is like as XML data.

Like the following...

ForLearn - vwFirst

<NDL>
<REPLICA 80257982:0030ACD6>
<VIEW OF36506E63:CADCC181-ON80257982:0030EA23>
<NOTE OF721DA42A:B3B04ECE-ON80257990:003A7B90>
<HINT>SERVERNAME</HINT>
<REM>ForLearn</REM>
</NDL>

So I tried into a lot of way finally I got the solution for that...

I have pasted the document link into my same time chat...

Now it came like the following...

Notes://serverName/802579820030ACD6/36506E63CADCC181802579820030EA23/721DA42AB3B04ECE80257990003A7B90

With the use of this we can easily send our document link to our client.

Wednesday, January 25, 2012

SetContentFromText Method in NotesRichTextItem

For NotesRichTextItem,

Call notesMIMEEntity.SetContentFromText( stream, contentType, encoding ),



In Notes 8.5.2,

We can use ENC_BASE64 as Encoding,

But for 8.5.1, it will not work...

I have tried this for one of my project, It showed "SetContextFromText is null"

I use 1727 for ENC_BASE64, It is working nice now.,


ENC_BASE64 (1727) -- Content-Transfer-Encoding is "base64"
ENC_EXTENSION (1731) -- Content-Transfer-Encoding is user-defined
ENC_IDENTITY_7BIT (1728) -- Content-Transfer-Encoding is "7bit"
ENC_IDENTITY_8BIT (1729) -- Content-Transfer-Encoding is "8bit"
ENC_IDENTITY_BINARY (1730) -- Content-Transfer-Encoding is "binary"
ENC_NONE (1725) -- no Content-Transfer-Encoding header
ENC_QUOTED_PRINTABLE (1726) -- Content-Transfer-Encoding is "quoted-printable"


In Notes 8.5.2,

We can use ENC_BASE64 as Encoding,

But for 8.5.1, which will not work...

I tried this for one of my project, It showed "SetContextFromText is null"

So We have to use 1727 for ENC_BASE64.,

Monday, January 23, 2012

Document context- Run Agent



Please check the below steps need to be done...

1. Check the Agent should be sign with Server ID or Administrator ID

2. Need to check the Run as Web user(Property) in Agent property.

3. Check your Agent Target - View Window or None

Wednesday, January 11, 2012

Usefull Link for Xpage - IBM Java classes

This is useful for us


IBM- Java classes

Sliding the Text in Xpages

Paste this into your xpage's source

<xp:eventHandler event="onclick" submit="false">

<xp:this.script>

<xp:scriptGroup>

<xe:alertAction
text="Sliding text to position 0, 1000">
</xe:alertAction>

<xe:dojofxSlideTo node="div1" duration="1500" left="100"
top="500">
</xe:dojofxSlideTo>


</xp:scriptGroup>

</xp:this.script>

</xp:eventHandler>

How to Import Javapackage into Xpages

Java Class



package com.Learn;

public class smallDBName {


public int add(int a, int b)
{
return a+b;
}
/**
* @param args
*/

}


Xpage -> Write the following code in Button Event

importPackage(com.Learn);
var a=new smallDBName();
getComponent("Name").setValue(@Text(a.add(2,6)))

ODBC in Xpages (Javascript)

try
{
print("Testing");
java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
var con:java.sql.Connection=java.sql.DriverManager.getConnection("jdbc:odbc:Datasource1","","");
var stmt:java.sql.Statement=con.createStatement();
var re:java.sql.ResultSet=stmt.executeQuery("SELECT * FROM employee");
var t=null;
while (re.next()) {
t=t + "\n" + rec.getString(1) + "\t" + rec.getString(2);
}
st.close();
getComponent("Name").setValue(t)
}
catch(Exception)
{
getComponent("Name").setValue("Error on Java Script");

Excel Export in Xpage

Enter this code in Xpage - after Render Response...

var exCon = facesContext.getExternalContext();

var writer = facesContext.getResponseWriter();

var response = exCon.getResponse();

var projects:NotesView = database.getView("vwFirst") //view name

var viewNav:NotesViewNavigator = projects.createViewNav();

var viewEnt:NotesViewEntry = viewNav.getFirst();

var output = "";

var i=0;

while (viewEnt != null) {

output += "<tr>";

output += "<td>" + viewEnt.getColumnValues()[0] + "</td>";

output += "<td>" + viewEnt.getColumnValues()[1] + "</td>"; //viewEnt.getColumnValues()

output += "<td>" + viewEnt.getColumnValues()[2] + "</td>";

output += "<td>" + viewEnt.getColumnValues()[3] + "</td>";

output += "<td>" + viewEnt.getColumnValues()[4] + "</td>";

output += "</tr>";

i=i+1;
viewEnt = viewNav.getNext(viewEnt);
}

response.setContentType("application/csv-tab-delimited-table;charset=utf-8");

response.setHeader("Cache-Control", "no-cache");

response.setHeader("Content-Disposition","attachment; filename=\"export.xls\"");

writer.write("<html>");

writer.write("<head>");

writer.write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>")

writer.write("</head>");

writer.write("<body>");

writer.write("<table>");

writer.write("<tr>");

for(var t=0;t<projects.getColumnNames().length;t++)
{
writer.write("<td><b>"+projects.getColumnNames()[t]+"</b></td>");
}


//writer.write("<td><b>ColumnName1</b></td>");

//writer.write("<td><b>ColumnName2</b></td>");

//writer.write("<td><b>ColumnName3</b></td>");

//writer.write("<td><b>ColumnName4</b></td>");

writer.write("</tr>");

writer.write(output);

writer.write("</table>");

writer.write("<body>");

writer.write("</html>");

writer.endDocument();

Wednesday, January 4, 2012

Scope Variables...

Four Type:

1.application Scope- Available to all

2.Session Scope- Available to current user

3.View Scope-Current page

4.request Scope- 1 Trip to server

//creating scoped variable

ex:

viewScope.put(“varName”,“value”) or viewScope.varName=value

//Retrieving a scoped variable

ex:

var temp = viewScope.get(“varName”) or var temp=viewScope.varName

Difference between ViewScope and RequestScope

Here i explained difference between ViewScope and request Scope by simple example.

step1:

create new X-pages and click source. Erase all code and put following code

<?xml version=”1.0″ encoding=”UTF-8″?>

<xp:view xmlns:xp=”http://www.ibm.com/xsp/core”>

<xp:this.afterPageLoad>

<xp:setValue binding=”#{viewScope.x}” value=”0″/>

</xp:this.afterPageLoad>

<xp:link escape=”true”

text=”#{javascript:viewScope.x=@Integer(viewScope.x)+1}”

id=”link1″>

<xp:eventHandler event=”onclick” submit=”true”

refreshMode=”complete” immediate=”false” save=”false”>

</xp:eventHandler>

</xp:link>

</xp:view>

step2:

Save that x-pages and click preview it shows 1. click 1 it shows count of how many time button click

From which example, the viewScope variable hold value till current page

step 3:

create newanother X-pages and click source. Erase all code and put following code

<?xml version=”1.0″ encoding=”UTF-8″?>

<xp:view xmlns:xp=”http://www.ibm.com/xsp/core”>

<xp:this.afterPageLoad>

<xp:setValue binding=”#{requestScope.x}” value=”0″/>

</xp:this.afterPageLoad>

<xp:link escape=”true”

text=”#{javascript:requestScope.x=@Integer(requestScope.x)+1}”

id=”link1″>

<xp:eventHandler event=”onclick” submit=”true”

refreshMode=”complete” immediate=”false” save=”false”>

</xp:eventHandler>

</xp:link>

</xp:view>
<?xml version=”1.0″ encoding=”UTF-8″?>
<xp:view xmlns:xp=”http://www.ibm.com/xsp/core”>
<xp:this.afterPageLoad>
<xp:setValue binding=”#{viewScope.x}” value=”0″/>
</xp:this.afterPageLoad>
<xp:link escape=”true”
text=”#{javascript:viewScope.x=@Integer(viewScope.x)+1}”
id=”link1″>
<xp:eventHandler event=”onclick” submit=”true”
refreshMode=”complete” immediate=”false” save=”false”>
</xp:eventHandler>
</xp:link>
</xp:view>

step4:

Save that x-pages and click preview it shows 1. click 1 it dont change. it show only 1.

Two example code are same . first example i used viewScope and second example i used requestScope .

requestscope Variable hold value untill request hit the server. so each time click link it hit server so each click the RequestScope variable cleared and set as a 0.

Export the documents to Excel using Xpages

The following is the code which is used to export the selected documents to excel in Xpages
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var projects:NotesView = database.getView(’EmployeeList’)
var viewNav:NotesViewNavigator = projects.createViewNav();
var viewEnt:NotesViewEntry = viewNav.getFirst();
var output:string = “”;
while (viewEnt != null) {
output += “<tr>”;
output += “<td>” + viewEnt.getColumnValues()[0]; + “</td>”;
output += “<td>” + viewEnt.getColumnValues()[1] + “</td>”;
output += “<td>” + viewEnt.getColumnValues()[2] + “</td>”;
output += “<td>” + viewEnt.getColumnValues()[3] + “</td>”;
output += “</tr>”;
viewEnt = viewNav.getNext(viewEnt);
}
response.setContentType(”application/vnd.ms-excel”);
response.setHeader(”Cache-Control”, “no-cache”);
response.setHeader(”Content-Disposition”,”attachment;filename=EmployeeDetails.xls”) ;
writer.write(”<table>”);
writer.write(”<thead><tr>”);
writer.write(”<td><b>EmployeeName</b></td>”);
writer.write(”<td><b>EmployeeId</b></td>”);
writer.write(”<td><b>Department</b></td>”);
writer.write(”<td><b>Designation</b></td>”);
writer.write(”</tr></thead>”);
writer.write(output);
writer.write(”</table>”);
writer.endDocument();

var exCon = facesContext.getExternalContext();

var writer = facesContext.getResponseWriter();

var response = exCon.getResponse();

var projects:NotesView = database.getView(’EmployeeList’)//view name

var viewNav:NotesViewNavigator = projects.createViewNav();

var viewEnt:NotesViewEntry = viewNav.getFirst();

var output:string = “”;

while (viewEnt != null) {

output += “<tr>”;

output += “<td>” + viewEnt.getColumnValues()[0]; + “</td>”;

output += “<td>” + viewEnt.getColumnValues()[1] + “</td>”;

output += “<td>” + viewEnt.getColumnValues()[2] + “</td>”;

output += “<td>” + viewEnt.getColumnValues()[3] + “</td>”;

output += “</tr>”;

viewEnt = viewNav.getNext(viewEnt);

}

response.setContentType(”application/vnd.ms-excel”);

response.setHeader(”Cache-Control”, “no-cache”);

response.setHeader(”Content-Disposition”,”attachment;filename=EmployeeDetails.xls”) ;

writer.write(”<table>”);

writer.write(”<thead><tr>”);

writer.write(”<td><b>ColumnName1</b></td>”);

writer.write(”<td><b>ColumnName2</b></td>”);

writer.write(”<td><b>ColumnName3</b></td>”);

writer.write(”<td><b>ColumnName4</b></td>”);

writer.write(”</tr></thead>”);

writer.write(output);

writer.write(”</table>”);

writer.endDocument();

Translate functionality for RICHTEXT [Change Font and Font size]

Call this agent in QuerySave of a document

@Command([EditGotoField];”Your Field Name”);

@Command([EditSelectAll]);

@Command([TextSetFontFace];”Arial”);

@Command([TextSetFontSize];”9″);

Export to Excel in Lotus Notes [LS]

The following is the Agent which is used to import the datas from excel using xpages.

1. Create an excel sheet relevant to the Form

2. Write the following code in the Agent
Sub Initialize
Print “agent is runing”
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = New NotesDocument(db)
Dim One As String
Dim xlFilename As String
Dim filepath As Variant
Dim row As Integer
Dim written As Integer
‘// Connect to Excel and open the file. Start pulling over the records.
Dim Excel As Variant
Dim xlWorkbook As Variant
Dim xlSheet As Variant
‘filepath=ws.Openfiledialog(False, ” Open excel file” ,”*.xls”, “E:\New Folder”, “employeeDetails.xls”)
filepath=”E:\New Folder\Emp_Details.xls”
xlFilename=filepath
Print “File path is :” +filepath
Print “Connecting to Excel…”
Set Excel = createobject( “Excel.Application” )
Excel.Visible = False ‘// Don’t display the Excel window
print “Opening ” & xlFilename & “…”
Excel.Workbooks.Open(xlFilename) ‘// Open the Excel file
Set xlWorkbook = Excel.ActiveWorkbook
Set xlSheet = xlWorkbook.ActiveSheet
‘// Cycle through the rows of the Excel file, pulling the data over to Notes
GoTo Records
print “Disconnecting from Excel…”
xlWorkbook.Close False ‘// Close the Excel file without saving (we made no changes)
Excel.Quit ‘// Close Excel
Set Excel = Nothing ‘// Free the memory
Records:
row = 1 ‘// Integers intialize to zero
written = 0
‘MsgBox “Starting import from Excel file…”
Do While True
Finish:
With xlSheet
row = row + 1
Set doc = db.createdocument ‘// Create a new doc
doc.Form = “frm_employeeDetails”
If .Cells( row, 1 ).Value=”" Then
Exit Sub
End If
doc.name = .Cells( row, 1 ).Value
doc.department = .Cells(row, 2 ).Value
doc.designation = .Cells(row, 3).value
doc.mobno = .Cells(row, 4).Value
Call doc.Save( True, True ) ‘// Save the new doc
‘GoTo Done
written = written + 1
Print Str(written)
If .Cells( row, 1 ).Value = “” Then
GoTo Done
End If
End With
Loop
Return
Done:
print “Import Complete – Total number of documents imported —> ” & written
End Sub

Sub Initialize

Print “agent is runing”

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = New NotesDocument(db)

Dim One As String

Dim xlFilename As String

Dim filepath As Variant

Dim row As Integer

Dim written As Integer

‘// Connect to Excel and open the file. Start pulling over the records.

Dim Excel As Variant

Dim xlWorkbook As Variant

Dim xlSheet As Variant

‘filepath=ws.Openfiledialog(False, ” Open excel file” ,”*.xls”, “E:\New Folder”, “employeeDetails.xls”)\\Gine the Folder name here

filepath=”E:\New Folder\Emp_Details.xls”

xlFilename=filepath

Print “File path is :” +filepath

Print “Connecting to Excel…”

Set Excel = createobject( “Excel.Application” )

Excel.Visible = False ‘// Don’t display the Excel window

print “Opening ” & xlFilename & “…”

Excel.Workbooks.Open(xlFilename) ‘// Open the Excel file

Set xlWorkbook = Excel.ActiveWorkbook

Set xlSheet = xlWorkbook.ActiveSheet

‘// Cycle through the rows of the Excel file, pulling the data over to Notes

GoTo Records

print “Disconnecting from Excel…”

xlWorkbook.Close False ‘// Close the Excel file without saving (we made no changes)

Excel.Quit ‘// Close Excel

Set Excel = Nothing ‘// Free the memory

Records:

row = 1 ‘// Integers intialize to zero

written = 0

Do While True

Finish:

With xlSheet

row = row + 1

Set doc = db.createdocument ‘// Create a new doc

doc.Form = “frm_employeeDetails”

If .Cells( row, 1 ).Value=”" Then

Exit Sub

End If

doc.name = .Cells( row, 1 ).Value

doc.department = .Cells(row, 2 ).Value

doc.designation = .Cells(row, 3).value

doc.mobno = .Cells(row, 4).Value

Call doc.Save( True, True ) ‘// Save the new doc

‘GoTo Done

written = written + 1

Print Str(written)

If .Cells( row, 1 ).Value = “” Then

GoTo Done

End If

End With

Loop

Return

Done:

print “Import Complete – Total number of documents imported —> ” & written

End Sub
1. Create one button in Xpage and add the following code in the PostSaveDocument in the DataSource in the page which is used to execute the agent
var agen=database.getAgent(”[agentNae]“);
var uid=document2.getDocument().getNoteID();
agen.run(uid);

Html to Pdf using Java

The following Java Code is used to convert the HTML content into PDF

import java.io.*;

import java.io.FileOutputStream;
import org.xhtmlrenderer.pdf.ITextRenderer;
public class pdfCreation {

/**
* @Purpose : Converting html file into PDF.
* External jar file used iText-2.0.8.jar, core-renderer.jar
* xml-apis-xerces-2.9.1.jar
*/
public static void main(String[] args) {
try{
//html file path
String inputFile=”C:\\workspace\\html2Pdf\\src\\pack1\\sample.html”;
//Output pdf file path
String outputFP=”C:\\sample.pdf”;
File inputHTMLFile=new File(inputFile);
if(!inputHTMLFile.exists()){
System.out.println(”Input html File does not exists!”);
System exit(0);
}
String url=inputHTMLFile.toURI().toURL().toString();
OutputStream os=new FileOutputStream(outputFP);
ITextRenderer renderer=new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
System.out.println(”HTML file was converted into PDF”);
}
catch(Exception e){
e.printStackTrace();
}
}
}

Code to move the selected documents by enabling the folder in xpages


The following is the code which is used to move the selected documents by getting the selected document ID’s and moving it to the folder by enabling the new folder

var viewPanel=getComponent(”viewPanel1″);//get the componet of viewPanel

var docIDArray=viewPanel.getSelectedIds(); //get the array of document ids

var i;

database.enableFolder(”Temp1");

var projects:NotesView=database.getView(”Temp1");

var ndc:NotesDocumentCollection=projects.getAllEntries();

ndc.removeAllFromFolder(”Temp1");

if(docIDArray.length!=0)

{

for(i=0;i&ltdocIDArray.length;i++)

{

var docId=docIDArray[i];

var doc:NotesDocument=database.getDocumentByID(docId);

doc.putInFolder(”Temp1");

}

}


var viewPanel=getComponent(”viewPanel1");//get the componet of viewPanel


var docIDArray=viewPanel.getSelectedIds(); //get the array of document ids


var i;


database.enableFolder(”Temp1");


var projects:NotesView=database.getView(”view name“);


var ndc:NotesDocumentCollection=projects.getAllEntries();


ndc.removeAllFromFolder(”Temp1″);


if(docIDArray.length!=0)


{


for(i=0;i&ltdocIDArray.length;i++)


{


var docId=docIDArray[i];


var doc:NotesDocument=database.getDocumentByID(docId);


doc.putInFolder(”Temp1″);


}


}