Code Post Number OneJust a little bit of stuff to shareEarth Date 2008.06.20 |
It seems there is a never ending batch of little tasks I need to do that I can't seem to find reusable code for. So I write it myself. Problem is that I don't seeing anyone else on my team using it or even interested in knowing what the stuff does... strange. So I'm gonna start putting it out here.
I need to thank a conversation with my pal Phil as the root cause for my new found desire to share. Somewhere in our conversation the statement "If you don't share your code then it doesn't do anyone else any good" just inspired me.
Simple stuff for the most part, at this point it is sitting in lotusScript.. though Java and Ruby aren't out of the picture. That said... Here's post one under "Code"
Since this is the first in the Code:LotusScript thread, let's just empty out today's scratch pads:
1. "Dang It! How could I know they didn't have a C drive... stupid Citrix." - I've been concerned about my LotusScript portability to *nix for awhile... but when it blew up in a Citrix Windows environment I felt really dumb. You see, people aren't required to accept Citrix full access when starting up a program (even Notes on Citrix) therefore previous assumptions that there will be a C: drive are GONE for my apps. So now i need to check for a mount point in which I can write logs for some apps. Dir$ works fine, so I just made a reusable function and loop pattern to handle it.
Here's the Function:
Function checkForMount( mount As String ) As Boolean
On Error Goto erh
Dim fileName As String
checkForMount = true
fileName$ = Dir$(mount, 0)
Exit Function
erh:
checkForMount=is_goodMount
Exit Function
End Function
Okay... easy enough now I get to use it.
<....blah blah blah...>
sDte = Format$( Now, "yyyymmdd-hhmmss")
theMount = "c:\"
' * Feature to make sure we are going to be able to write our log
If Not(checkForMount(theMount)) Then
Dim theNewMount As String
Dim is_continuable As Boolean
is_continuable=True
theNewMount = currentWS.Prompt(3,"Could not mount drive...", _
"Could not find '" + theMount + "'" + Chr(13) + "Please enter a valid mount point below", _
theMount)
If theNewMount="" Then is_continuable=False
If is_continuable Then
While is_continuable
If checkForMount(theNewMount) Then
theMount = theNewMount
is_Continuable = False
Else
theNewMount = currentWS.Prompt(3,"Could not mount drive...", _
"Could not find '" + theNewMount + "'" + Chr(13) + "Please enter a valid mount point below", _
theMount)
End If
If theNewMount="" Then is_continuable=False
Wend
If Len(theNewMount)=0 Then Exit Sub
Else
Exit Sub
End If
End If
Print ""
sImportLog = theMount + sDte + Cstr(s.CurrentAgent.name)+ "-" + sLogString + "log.txt"
logXMLGEN.OpenFileLog sImportLog
<...blah blah blah...>
Okay... what's it all do?
If the default drive of C:\ causes an error in the Dir$ call then the user will be prompted to enter a valid drive/mount point. The loop will continue to prompt the user until one of 2 things happen:
That's it for that scratch pad, let's see what else I have out here...
This one is kinda fun. In Lotus Notes code you want to get a particular value from a "parent" document which you have the UNID for. The script takes the field you are looking for and the parent's universalID (which we save on our "child" documents)
Function getFieldValueStringFromParent( fieldName As String, parentUNID As String ) As String
On Error Goto erh
Dim currentSession As New NotesSession
Dim currentDB As NotesDatabase
Dim unidView As NotesView
Dim parentDoc As NotesDocument
getFieldValueStringFromParent=""
Set currentDB = currentSession.CurrentDatabase
Set parentDoc = currentDB.getDocumentByUNID( parentUNID )
If Not( parentDoc Is Nothing ) Then
If parentDoc.HasItem( fieldName ) Then
If Len(Cstr(parentDoc.getItemValue(fieldName)(0)))>0 Then
getFieldValueStringFromParent = Cstr(parentDoc.getItemValue(fieldName)(0))
End If
End If
End If
Exit Function
erh:
getFieldValueStringFromParent=""
Exit Function
End Function
... That's a start. I think I'll unload my globalFunctions library next.