public void createFolder(String FolderPath)
{
try{
/* By default the folders will be created in your workspace directory
* Hence it is advisable to provide a proper path where you can find these directories easily
*/
(new java.io.File(FolderPath)).mkdirs();
}catch (Exception e){//Catch exception if any
e.printStackTrace();
}
}//END OF createFolder
Share your thoughts and find that its getting better every day. This work of mine helps me realize that.
Tuesday, March 16, 2010
Check whether a directory exists or not (in java)
public boolean isDirectory(String folder)
{
java.io.File directoryName = new java.io.File(folder);
return directoryName.isDirectory();
} //END OF isDirectory
{
java.io.File directoryName = new java.io.File(folder);
return directoryName.isDirectory();
} //END OF isDirectory
Convert image file Attachment into a image resource
The following functions will help you convert image files attached in documents into image resources in the same database. Probable you may have to remove fragments that you dont want to use.
'**************************************************************
'@Purpose : To process file attachments and
' convert the same into image resources in the current database
'**************************************************************
Private Function ProcessAttachments(imageName As String,flag As String,imagePath As String) As Boolean
'mark the flow of control getting inside the current function
ProcessAttachments=False
'declare variables and objects necessary for further manipulations
Dim session As New notessession
Dim tempFolderPath As String
Dim directory As String
Dim db As NotesDatabase
Dim tempDoc As NotesDocument
Dim entity As NotesMimeEntity
Dim imageSize As Long
'handle errors in case of abrupt termination
On Error Goto processAttErrHandler
'set the handle of the current database
Set db = session.CurrentDatabase
directory = tempFolderPath
'create a temporary document to contain the mime entity of the images
Set tempDoc = db.CreateDocument
If Not( CreateMIMEEntity(imagePath, tempDoc, entity, imageSize)) Then
Exit Function
End If
'create a dxl file of the created mime type
If Not CreateDXLFile( imagePath, entity, imageSize) Then
Exit Function
End If
'import the created dxl file as image resource
If Not ImportDXLFile( imagePath, db) Then
Exit Function
End If
'destroy the file created in the temporary folder
Kill imagePath
'mark the flow of control getting out of the current function
ProcessAttachments=True
Exit Function
'log the errors that resulted in abrupt termination
processAttErrHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***" _
& Cstr(Err) & "*** in Method ""ProcessAttachments"" in script Library ""lsLookAndFeel"""
Exit Function
End Function
'****************************************************************
'@Created : 2008/09/12
'@Purpose : To create a dxl file that resembles the dxl of design elements in Image resources
' provided the mime type of an image file
'****************************************************************
Private Function CreateDXLFile( imagePath As String, entity As NotesMimeEntity, imageSize As Long)
'mark the flow of control getting inside the current function
CreateDXLFile=False
'declare all variables and objects necessary for furhter manipulation
Dim session As New notessession
Dim stream As NotesStream
Dim directory As String
Dim imageName As String
'initiation
'handle errors in case of abrupt termination
On Error Goto errHandler
If Instr(imagePath, "\") <> 0 Then
directory = Strleftback(imagePath, "\") & "\"
imageName = Strrightback(imagePath, "\")
Else
directory = Strleftback(imagePath, "/") & "/"
imageName = Strrightback(imagePath, "/")
End If
'create a stream
Set stream = session.CreateStream
If Not stream.Open(directory & Strleftback(imageName, ".") & ".dxl", "ISO-8859-1") Then
Error 1405, "Cannot create file " & directory & Strleftback(imageName, ".") & ".dxl on the server."
End If
Call stream.WriteText({})
Call stream.WriteText({
Call stream.WriteText({ noreplace='true' publicaccess='false' designerversion='7'>})
If Right(Lcase(imageName), 4) = ".gif" Then
Call stream.WriteText({})
Call stream.WriteText(entity.ContentAsText)
Call stream.WriteText({ })
Else
Call stream.WriteText({})
Call stream.WriteText(entity.ContentAsText)
Call stream.WriteText({ })
End If
Call stream.WriteText({})
Call stream.WriteText(Cstr(imageSize) & { })
Call stream.WriteText({})
If Right(Lcase(imageName), 4) = ".gif" Then
Call stream.WriteText({image/gif})
Else
Call stream.WriteText({image/jpeg})
End If
Call stream.WriteText({ })
Call stream.WriteText({})
Call stream.WriteText(Format$(Now, "YYYYMMDD") & "T" & Format$(Now, "HHMMSS") & ",00-00")
Call stream.WriteText({ })
Call stream.WriteText({ })
Call stream.Close
'mark the flow of control movingout of the current function
CreateDXLFile=True
Exit Function
'log the error that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***" _
& Cstr(Err) & "*** in Method ""CreateDXLFile"" in script Library ""lsLookAndFeel"""
Exit Function
End Function
'****************************************************************
'@Created : 2008/09/12
'@Purpose : To create mime content of an image file
'****************************************************************
Function CreateMIMEEntity( imagePath As String, tempDoc As NotesDocument, entity As NotesMimeEntity, imageSize As Long)As Boolean
'mark the flow of control getting inside the current function
CreateMIMEEntity=False
'declare variables and objects necessary for further manipulation
Dim session As New notessession
Dim stream As NotesStream
'initiation
'handler errors in case of abrupt termination
On Error Goto mimeErrHandler
'create a stream object
Set stream = session.CreateStream
If Not stream.Open(imagePath) Then
Error 1404, "Cannot open file " & imagePath & " for processing."
Exit Function
End If
imageSize = stream.Bytes
Call tempDoc.ReplaceItemValue("Form", "Temporary Document")
Set entity = tempDoc.CreateMIMEEntity
If Right(Lcase(imagePath), 4) = ".gif" Then
Call entity.SetContentFromBytes(stream, "image/gif", ENC_NONE)
Else
Call entity.SetContentFromBytes(stream, "image/jpeg", ENC_NONE)
End If
Call entity.EncodeContent(ENC_BASE64)
Call stream.Close
'mark the flow of control moving out of the current function
CreateMIMEEntity=True
Exit Function
mimeErrHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***" _
& Cstr(Err) & "*** in Method ""CreateMIMEEntity"" in script Library ""lsLookAndFeel"""
Exit Function
End Function
'****************************************************************
'@Created : 2008/09/12
'@Purpose : To import a dxl file in to the current database
'****************************************************************
Private Function ImportDXLFile( imagePath As String, db As NotesDatabase) As Boolean
'mark the flow of control getting inside the current function
ImportDXLFile=False
'declaring variables and objects necessary for further manipulation
Dim session As New notessession
Dim stream As NotesStream
Dim importer As NotesDXLImporter
Dim dxlPath As String
'initiation
'handle errors in case of abrupt termination
On Error Goto errHandler
dxlPath = Strleftback(imagePath, ".") & ".dxl"
Set stream = session.CreateStream
If Not stream.Open(dxlPath, "ISO-8859-1") Then
Error 1406, "Cannot open file " & dxlPath & " after it was created."
End If
Set importer = session.CreateDXLImporter(stream, db)
importer.ReplaceDBProperties = False
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_CREATE
Call importer.Process
Call stream.Close
'mark the flow of control movingout of the current function
ImportDXLFile=True
Exit Function
'log the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***" _
& Cstr(Err) & "*** in Method ""ImportDXLFile"" in script Library ""lsLookAndFeel"""
Exit Function
End Function
'**************************************************************
'@Purpose : To process file attachments and
' convert the same into image resources in the current database
'**************************************************************
Private Function ProcessAttachments(imageName As String,flag As String,imagePath As String) As Boolean
'mark the flow of control getting inside the current function
ProcessAttachments=False
'declare variables and objects necessary for further manipulations
Dim session As New notessession
Dim tempFolderPath As String
Dim directory As String
Dim db As NotesDatabase
Dim tempDoc As NotesDocument
Dim entity As NotesMimeEntity
Dim imageSize As Long
'handle errors in case of abrupt termination
On Error Goto processAttErrHandler
'set the handle of the current database
Set db = session.CurrentDatabase
directory = tempFolderPath
'create a temporary document to contain the mime entity of the images
Set tempDoc = db.CreateDocument
If Not( CreateMIMEEntity(imagePath, tempDoc, entity, imageSize)) Then
Exit Function
End If
'create a dxl file of the created mime type
If Not CreateDXLFile( imagePath, entity, imageSize) Then
Exit Function
End If
'import the created dxl file as image resource
If Not ImportDXLFile( imagePath, db) Then
Exit Function
End If
'destroy the file created in the temporary folder
Kill imagePath
'mark the flow of control getting out of the current function
ProcessAttachments=True
Exit Function
'log the errors that resulted in abrupt termination
processAttErrHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***" _
& Cstr(Err) & "*** in Method ""ProcessAttachments"" in script Library ""lsLookAndFeel"""
Exit Function
End Function
'****************************************************************
'@Created : 2008/09/12
'@Purpose : To create a dxl file that resembles the dxl of design elements in Image resources
' provided the mime type of an image file
'****************************************************************
Private Function CreateDXLFile( imagePath As String, entity As NotesMimeEntity, imageSize As Long)
'mark the flow of control getting inside the current function
CreateDXLFile=False
'declare all variables and objects necessary for furhter manipulation
Dim session As New notessession
Dim stream As NotesStream
Dim directory As String
Dim imageName As String
'initiation
'handle errors in case of abrupt termination
On Error Goto errHandler
If Instr(imagePath, "\") <> 0 Then
directory = Strleftback(imagePath, "\") & "\"
imageName = Strrightback(imagePath, "\")
Else
directory = Strleftback(imagePath, "/") & "/"
imageName = Strrightback(imagePath, "/")
End If
'create a stream
Set stream = session.CreateStream
If Not stream.Open(directory & Strleftback(imageName, ".") & ".dxl", "ISO-8859-1") Then
Error 1405, "Cannot create file " & directory & Strleftback(imageName, ".") & ".dxl on the server."
End If
Call stream.WriteText({})
Call stream.WriteText({
Call stream.WriteText({ noreplace='true' publicaccess='false' designerversion='7'>})
If Right(Lcase(imageName), 4) = ".gif" Then
Call stream.WriteText({
Call stream.WriteText(entity.ContentAsText)
Call stream.WriteText({
Else
Call stream.WriteText({
Call stream.WriteText(entity.ContentAsText)
Call stream.WriteText({
End If
Call stream.WriteText({
Call stream.WriteText(Cstr(imageSize) & {
Call stream.WriteText({
If Right(Lcase(imageName), 4) = ".gif" Then
Call stream.WriteText({image/gif})
Else
Call stream.WriteText({image/jpeg})
End If
Call stream.WriteText({
Call stream.WriteText({
Call stream.WriteText(Format$(Now, "YYYYMMDD") & "T" & Format$(Now, "HHMMSS") & ",00-00")
Call stream.WriteText({
Call stream.WriteText({
Call stream.Close
'mark the flow of control movingout of the current function
CreateDXLFile=True
Exit Function
'log the error that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***" _
& Cstr(Err) & "*** in Method ""CreateDXLFile"" in script Library ""lsLookAndFeel"""
Exit Function
End Function
'****************************************************************
'@Created : 2008/09/12
'@Purpose : To create mime content of an image file
'****************************************************************
Function CreateMIMEEntity( imagePath As String, tempDoc As NotesDocument, entity As NotesMimeEntity, imageSize As Long)As Boolean
'mark the flow of control getting inside the current function
CreateMIMEEntity=False
'declare variables and objects necessary for further manipulation
Dim session As New notessession
Dim stream As NotesStream
'initiation
'handler errors in case of abrupt termination
On Error Goto mimeErrHandler
'create a stream object
Set stream = session.CreateStream
If Not stream.Open(imagePath) Then
Error 1404, "Cannot open file " & imagePath & " for processing."
Exit Function
End If
imageSize = stream.Bytes
Call tempDoc.ReplaceItemValue("Form", "Temporary Document")
Set entity = tempDoc.CreateMIMEEntity
If Right(Lcase(imagePath), 4) = ".gif" Then
Call entity.SetContentFromBytes(stream, "image/gif", ENC_NONE)
Else
Call entity.SetContentFromBytes(stream, "image/jpeg", ENC_NONE)
End If
Call entity.EncodeContent(ENC_BASE64)
Call stream.Close
'mark the flow of control moving out of the current function
CreateMIMEEntity=True
Exit Function
mimeErrHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***" _
& Cstr(Err) & "*** in Method ""CreateMIMEEntity"" in script Library ""lsLookAndFeel"""
Exit Function
End Function
'****************************************************************
'@Created : 2008/09/12
'@Purpose : To import a dxl file in to the current database
'****************************************************************
Private Function ImportDXLFile( imagePath As String, db As NotesDatabase) As Boolean
'mark the flow of control getting inside the current function
ImportDXLFile=False
'declaring variables and objects necessary for further manipulation
Dim session As New notessession
Dim stream As NotesStream
Dim importer As NotesDXLImporter
Dim dxlPath As String
'initiation
'handle errors in case of abrupt termination
On Error Goto errHandler
dxlPath = Strleftback(imagePath, ".") & ".dxl"
Set stream = session.CreateStream
If Not stream.Open(dxlPath, "ISO-8859-1") Then
Error 1406, "Cannot open file " & dxlPath & " after it was created."
End If
Set importer = session.CreateDXLImporter(stream, db)
importer.ReplaceDBProperties = False
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_CREATE
Call importer.Process
Call stream.Close
'mark the flow of control movingout of the current function
ImportDXLFile=True
Exit Function
'log the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***" _
& Cstr(Err) & "*** in Method ""ImportDXLFile"" in script Library ""lsLookAndFeel"""
Exit Function
End Function
Labels:
DXL,
Lotus Notes,
Lotusscript
Tuesday, March 9, 2010
Function to Enable or Disable a scheduled agent (#2) - Added param
Function scheduledAgentSetEnabled(enable As Boolean, targetDB As NotesDatabase,scheduledAgentName As String) As Boolean
'***************************************************************
'@Purpose : To enable or disable a scheduled agent in target database
'@Param : enable - boolean, true if agent is to be enabled and false otherwise
'@Param : targetDB - NotesDatabase, database in which the agents have to be processed
'@Param : scheduledAgentName - String, name of the agent on which the operation has to made
'@Name : scheduledAgentSetEnabled
'@Author : Karthikeyan A
'@Return : Boolean. True if the operation completes successfully and false other wise
'***************************************************************
'mark the flow of control getting inside the current function
scheduledAgentSetEnabled=False
'constants used in this function
Const TITLE_ITEM="$Title"
Const ASSIST_FLAG_ITEM="$AssistFlags"
'declare variables and objects necessary for further manipulation
Dim nc As notesnotecollection
Dim desDoc As NotesDocument
Dim noteID As String
Dim assistFlags As String
'handle errors in case of abrupt termination
On Error Goto errHandler
If Not targetDB.IsOpen Then
Exit Function
End If
'get the notes collection of all the agents in the current database
Set nc=targetDB.CreateNoteCollection(False)
nc.SelectAgents=True
Call nc.BuildCollection()
'get the first noteid from the notes design document collection
noteID=nc.GetFirstNoteId
'loop through the design document collection using the noteIDs and enable or diable the agent whose title matches
'input parameter- agent name
Set desDoc=targetDB.GetDocumentByID(noteID)
While Not desDoc Is Nothing
If Ucase(desDoc.GetItemValue(TITLE_ITEM)(0))=Ucase(scheduledAgentName) Then
assistFlags=desDoc.GetItemValue(ASSIST_FLAG_ITEM)(0)
If enable Then
If Not Instr(Ucase(assistFlags),"E") Then
assistFlags=assistFlags & "E"
End If
Else
While Instr(Ucase(assistFlags),"E")
assistFlags=Replace(Ucase(assistFlags),"E","")
Wend
End If
Call desDoc.ReplaceItemValue(ASSIST_FLAG_ITEM,assistFlags)
Call desDoc.Save(True,False)
End If
noteID=nc.GetNextNoteId(noteID)
Set desDoc=targetDB.GetDocumentByID(noteID)
Wend
'mark the flow of control moving out of the current function
scheduledAgentSetEnabled=True
Exit Function
'inform the user regarding the errors that resulted in abrupt termination
errHandler:
If Err=4270 Then Exit Function
Msgbox "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Print "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Exit Function
End Function
'***************************************************************
'@Purpose : To enable or disable a scheduled agent in target database
'@Param : enable - boolean, true if agent is to be enabled and false otherwise
'@Param : targetDB - NotesDatabase, database in which the agents have to be processed
'@Param : scheduledAgentName - String, name of the agent on which the operation has to made
'@Name : scheduledAgentSetEnabled
'@Author : Karthikeyan A
'@Return : Boolean. True if the operation completes successfully and false other wise
'***************************************************************
'mark the flow of control getting inside the current function
scheduledAgentSetEnabled=False
'constants used in this function
Const TITLE_ITEM="$Title"
Const ASSIST_FLAG_ITEM="$AssistFlags"
'declare variables and objects necessary for further manipulation
Dim nc As notesnotecollection
Dim desDoc As NotesDocument
Dim noteID As String
Dim assistFlags As String
'handle errors in case of abrupt termination
On Error Goto errHandler
If Not targetDB.IsOpen Then
Exit Function
End If
'get the notes collection of all the agents in the current database
Set nc=targetDB.CreateNoteCollection(False)
nc.SelectAgents=True
Call nc.BuildCollection()
'get the first noteid from the notes design document collection
noteID=nc.GetFirstNoteId
'loop through the design document collection using the noteIDs and enable or diable the agent whose title matches
'input parameter- agent name
Set desDoc=targetDB.GetDocumentByID(noteID)
While Not desDoc Is Nothing
If Ucase(desDoc.GetItemValue(TITLE_ITEM)(0))=Ucase(scheduledAgentName) Then
assistFlags=desDoc.GetItemValue(ASSIST_FLAG_ITEM)(0)
If enable Then
If Not Instr(Ucase(assistFlags),"E") Then
assistFlags=assistFlags & "E"
End If
Else
While Instr(Ucase(assistFlags),"E")
assistFlags=Replace(Ucase(assistFlags),"E","")
Wend
End If
Call desDoc.ReplaceItemValue(ASSIST_FLAG_ITEM,assistFlags)
Call desDoc.Save(True,False)
End If
noteID=nc.GetNextNoteId(noteID)
Set desDoc=targetDB.GetDocumentByID(noteID)
Wend
'mark the flow of control moving out of the current function
scheduledAgentSetEnabled=True
Exit Function
'inform the user regarding the errors that resulted in abrupt termination
errHandler:
If Err=4270 Then Exit Function
Msgbox "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Print "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Exit Function
End Function
Labels:
Lotus Notes,
Lotusscript
Query String in XPages
Assuming that you pass parameters to xpages as indicated in the following link....
http://xyz.com/abc.xsp?solo="polo"
To retrieve or extract parameters.
var externalContext=facesContext.getExternalContext();
var servletRequest=externalContext.getRequest();
var queryString=servletRequest.getQueryString();
return queryString
it will return solo=polo.
You can also perform the following operation.
var exCon = facesContext.getExternalContext();
var request = exCon.getRequest(); // This is the actual HTTP servlet request...
var paramValue = request.getParameter("paramName");
return paramValue;
it will return polo.
http://xyz.com/abc.xsp?solo="polo"
To retrieve or extract parameters.
var externalContext=facesContext.getExternalContext();
var servletRequest=externalContext.getRequest();
var queryString=servletRequest.getQueryString();
return queryString
it will return solo=polo.
You can also perform the following operation.
var exCon = facesContext.getExternalContext();
var request = exCon.getRequest(); // This is the actual HTTP servlet request...
var paramValue = request.getParameter("paramName");
return paramValue;
it will return polo.
Function to Enable or Disable a scheduled agent
Function scheduledAgentSetEnabled(enable As Boolean, scheduledAgentName As String) As Boolean
'***************************************************************
'@Purpose : To enable or disable a scheduled agent
'@Name : scheduledAgentSetEnabled
'@Author : Karthikeyan A
'@Return : Boolean. True if the operation completes successfully and false other wise
'***************************************************************
'mark the flow of control getting inside the current function
scheduledAgentSetEnabled=False
'constants used in this function
Const TITLE_ITEM="$Title"
Const ASSIST_FLAG_ITEM="$AssistFlags"
'declare variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim currDB As notesdatabase
Dim nc As notesnotecollection
Dim desDoc As NotesDocument
Dim noteID As String
Dim assistFlags As String
'handle errors in case of abrupt termination
On Error Goto errHandler
'set the handle for the current database
Set currDB=session.CurrentDatabase
'get the notes collection of all the agents in the current database
Set nc=currDB.CreateNoteCollection(False)
nc.SelectAgents=True
Call nc.BuildCollection()
'get the first noteid from the notes design document collection
noteID=nc.GetFirstNoteId
'loop through the design document collection using the noteIDs and enable or diable the agent whose title matches
'input parameter- agent name
Set desDoc=currDB.GetDocumentByID(noteID)
While Not desDoc Is Nothing
If Ucase(desDoc.GetItemValue(TITLE_ITEM)(0))=Ucase(scheduledAgentName) Then
assistFlags=desDoc.GetItemValue(ASSIST_FLAG_ITEM)(0)
If enable Then
If Not Instr(Ucase(assistFlags),"E") Then
assistFlags=assistFlags & "E"
End If
Else
While Instr(Ucase(assistFlags),"E")
assistFlags=Replace(Ucase(assistFlags),"E","")
Wend
End If
Call desDoc.ReplaceItemValue(ASSIST_FLAG_ITEM,assistFlags)
Call desDoc.Save(True,False)
End If
noteID=nc.GetNextNoteId(noteID)
Set desDoc=currDB.GetDocumentByID(noteID)
Wend
'mark the flow of control moving out of the current function
scheduledAgentSetEnabled=True
Exit Function
'inform the user regarding the errors that resulted in abrupt termination
errHandler:
If Err=4270 Then Exit Function
Msgbox "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Print "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Exit Function
End Function
'***************************************************************
'@Purpose : To enable or disable a scheduled agent
'@Name : scheduledAgentSetEnabled
'@Author : Karthikeyan A
'@Return : Boolean. True if the operation completes successfully and false other wise
'***************************************************************
'mark the flow of control getting inside the current function
scheduledAgentSetEnabled=False
'constants used in this function
Const TITLE_ITEM="$Title"
Const ASSIST_FLAG_ITEM="$AssistFlags"
'declare variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim currDB As notesdatabase
Dim nc As notesnotecollection
Dim desDoc As NotesDocument
Dim noteID As String
Dim assistFlags As String
'handle errors in case of abrupt termination
On Error Goto errHandler
'set the handle for the current database
Set currDB=session.CurrentDatabase
'get the notes collection of all the agents in the current database
Set nc=currDB.CreateNoteCollection(False)
nc.SelectAgents=True
Call nc.BuildCollection()
'get the first noteid from the notes design document collection
noteID=nc.GetFirstNoteId
'loop through the design document collection using the noteIDs and enable or diable the agent whose title matches
'input parameter- agent name
Set desDoc=currDB.GetDocumentByID(noteID)
While Not desDoc Is Nothing
If Ucase(desDoc.GetItemValue(TITLE_ITEM)(0))=Ucase(scheduledAgentName) Then
assistFlags=desDoc.GetItemValue(ASSIST_FLAG_ITEM)(0)
If enable Then
If Not Instr(Ucase(assistFlags),"E") Then
assistFlags=assistFlags & "E"
End If
Else
While Instr(Ucase(assistFlags),"E")
assistFlags=Replace(Ucase(assistFlags),"E","")
Wend
End If
Call desDoc.ReplaceItemValue(ASSIST_FLAG_ITEM,assistFlags)
Call desDoc.Save(True,False)
End If
noteID=nc.GetNextNoteId(noteID)
Set desDoc=currDB.GetDocumentByID(noteID)
Wend
'mark the flow of control moving out of the current function
scheduledAgentSetEnabled=True
Exit Function
'inform the user regarding the errors that resulted in abrupt termination
errHandler:
If Err=4270 Then Exit Function
Msgbox "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Print "Error ***" & Error & "*** occured in line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err) & "*** in agent scheduledAgentSetEnabled(enable As Boolean, agentName As String)"
Exit Function
End Function
Labels:
Lotus Notes,
Lotusscript
Friday, March 5, 2010
My Unanswered questions in XPages
Assume that you have a Edit box control named "MyXSPField" on a XPage.
Now If I want to retrieve the value of the same on a button click, I can do it in the following ways,
i,
var fieldValue=document.getElementById("#{id:MyXSPField}").value
ii,
var computedId= "#{id:MyXSPField}";
var fieldValue=document.getElementById(computedId).value
But when I attempt to split the parameter as follows, no matter what ever way that I try, which makes sense to me, the attempt fails to give me the field value
i,
var editControlName="MyXSPField";
var computedId= "#{id:"+editControlName+"}";
var fieldValue=document.getElementById(computedId).value
ii,
var editControlName="MyXSPField";
var fieldValue=document.getElementById("#
{id:"+editControlName+"}").value
iii,
var editControlName="MyXSPField";
eval ('var fieldValue=document.getElementById("#
{id:"+editControlName+"}").value');
iv,
var editControlName="MyXSPField";
eval ('var fieldValue=document.getElementById("#
{id:"'+editControlName+'"}").value');
v,
I have tried replacing # by $ in all of the above mentioned attempts
Yes.. All of these attempts fail. I understand that I am breaking the EL (expression language) and that might be the issue....
But is there a way to instruct the XPage compiler to complile the dynamically created EL, 'cos this is a real worrying issue
Now If I want to retrieve the value of the same on a button click, I can do it in the following ways,
i,
var fieldValue=document.getElementById("#{id:MyXSPField}").value
ii,
var computedId= "#{id:MyXSPField}";
var fieldValue=document.getElementById(computedId).value
But when I attempt to split the parameter as follows, no matter what ever way that I try, which makes sense to me, the attempt fails to give me the field value
i,
var editControlName="MyXSPField";
var computedId= "#{id:"+editControlName+"}";
var fieldValue=document.getElementById(computedId).value
ii,
var editControlName="MyXSPField";
var fieldValue=document.getElementById("#
{id:"+editControlName+"}").value
iii,
var editControlName="MyXSPField";
eval ('var fieldValue=document.getElementById("#
{id:"+editControlName+"}").value');
iv,
var editControlName="MyXSPField";
eval ('var fieldValue=document.getElementById("#
{id:"'+editControlName+'"}").value');
v,
I have tried replacing # by $ in all of the above mentioned attempts
Yes.. All of these attempts fail. I understand that I am breaking the EL (expression language) and that might be the issue....
But is there a way to instruct the XPage compiler to complile the dynamically created EL, 'cos this is a real worrying issue
Labels:
Bugs,
Lotus Notes,
XPages
Wednesday, March 3, 2010
Getting an xpage component's id programatically when the same is clicked
Create an XPage.
Drag and Drop a button Control on to it and give the button a name and a label
Now on the events tab of the button, in the onclick event, select client side and type in the following code
var currId = thisEvent.target.id;
alert(currId);
Now and preview your XPage and click the button.
The result would be an alert box with the id of the button control that you have mentioned in the XPage. Again it will not be exactly the same but will be along with a pattern generated by the XPage and the same will be consistent.
Drag and Drop a button Control on to it and give the button a name and a label
Now on the events tab of the button, in the onclick event, select client side and type in the following code
var currId = thisEvent.target.id;
alert(currId);
Now and preview your XPage and click the button.
The result would be an alert box with the id of the button control that you have mentioned in the XPage. Again it will not be exactly the same but will be along with a pattern generated by the XPage and the same will be consistent.
"onload" Event in XPages
Developers who are experienced in traditional web applications in Lotus Notes it becomes a nightmare when they start to work with XPages.
One of the initial issues that I faced is - the struggle to gain control of the onload event in the XPages as the available events in the XPages like the afterPageLoad etc... only allows Serverside script and it becomes expensive to hit the server every time in terms of application's performance.
The following code fragment shall help people who face this issue, and will help them gain access to the XPage's onload event.
<script language="Javascript">
XSP.addOnLoad(alert('I am in XPage onload'));
</script></b>
Add this snippet of code in the Source panel and ensure that it is not nested inside any other existing tags.An ideal place would beneath the lines which say (sort of),
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
Now after performing the above step, preview your XPage and voila, you will get the alert saying "I am in XPage onload"
One of the initial issues that I faced is - the struggle to gain control of the onload event in the XPages as the available events in the XPages like the afterPageLoad etc... only allows Serverside script and it becomes expensive to hit the server every time in terms of application's performance.
The following code fragment shall help people who face this issue, and will help them gain access to the XPage's onload event.
<script language="Javascript">
XSP.addOnLoad(alert('I am in XPage onload'));
</script></b>
Add this snippet of code in the Source panel and ensure that it is not nested inside any other existing tags.An ideal place would beneath the lines which say (sort of),
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
Now after performing the above step, preview your XPage and voila, you will get the alert saying "I am in XPage onload"
Tuesday, March 2, 2010
Remote Desktop from command prompt
Open up the command prompt and type in the following command.
"mstsc" and press enter. This will bring up the remote desktop connection wizrd asking for the ip of the machine to which you want to remote to.
This is an alternate way for doing the following
Start-> All Programs-> Accessories-> Remote Desktop Connection
Also you can type the same in Run Dialog
Start-> Run-> mstsc and hit enter
"mstsc" and press enter. This will bring up the remote desktop connection wizrd asking for the ip of the machine to which you want to remote to.
This is an alternate way for doing the following
Start-> All Programs-> Accessories-> Remote Desktop Connection
Also you can type the same in Run Dialog
Start-> Run-> mstsc and hit enter
Subscribe to:
Posts (Atom)