Tag: Lotusscript

  • PDFCreator aansturen met LotusScript

    PDFCreator aansturen met LotusScript

    Voor een klant moest er een export gemaakt worden van alle Notes documenten in een database.
    Dit moest gebeuren door deze als PDF af te drukken.
    Als PDF printer heb ik gekozen voor de open source applicatie PDFCreator, dat makkelijk aan te sturen is en erg nette afdrukken maakt.
    Omdat er geen tijd was om te onderzoeken of dit op de achtergrond kon gebeuren heb ik gekozen om een eenvoudig script te maken dat via de Notes cliënt door een weergave loopt, elk document opent, de bestandsnaam aan PDFCreator doorgeeft via COM, afdrukt naar de default (PDF) printer, en het document sluit.

    Code

    Sub Initialize
    On Error GoTo ErrorHandler
    '....... Declare And Set items.....
    
    sPDFPath$ = "C:\"
    If Dir(sPDFPath$,16) = "" Then
    MsgBox sPDFPath$ & " kan niet worden geopend",16,"Export"
    End If
    
    Set PDFCreator = CreateObject("PDFCreator.clsPDFCreator")
    If Not PDFCreator.cStart("",True) Then
    MsgBox "PDF printer kan niet worden gestart",16,"Export"
    GoTo TheEnd
    End If
    
    Set Doc = View.GetFirstDocument
    Do Until Doc Is Nothing
    
    sPDFName$ = doc.NoteID & ".pdf"
    FileName$ = sPDFPath$ & sPDFName$
    If Not Dir(FileName$) = "" Then
    Kill FileName$
    End If
    
    With PDFCreator
    .cOption("UseAutosave") = 1
    .cOption("UseAutosaveDirectory") = 1
    .cOption("AutosaveDirectory") = sPDFPath$
    .cOption("AutosaveFilename") = sPDFName$
    .cOption("AutosaveFormat") = 0
    .cClearCache
    End With
    
    Set uiDoc = ws.EditDocument(False,Doc,True,"",True,True)
    Call uiDoc.Print(1)
    Call uiDoc.Close(True)
    Set uiDoc = Nothing
    
    If Not isFileCreated(FileName$) Then
    'Foutafhandeling
    End If
    Set Doc = View.GetNextDocument(Doc)
    Loop
    
    TheEnd:
    On Error Resume Next
    PDFCreator.cClose
    Set PDFCreator = Nothing
    Exit Sub
    
    ErrorHandler:
    MsgBox GetThreadInfo(1) & " " & Error & " (" & Err & ") op regel " & Erl & "."
    Resume TheEnd
    End Sub
    
    Function isFileCreated ( filePath As String ) As Boolean
    On Error GoTo errorHandler
    Dim counter As Integer
    Dim fSize As Long
    
    isFileCreated = False
    Do While Dir$(filePath$, 0) = ""
    If counter > 30 Then
    Exit Function
    End If
    Sleep 1
    counter = counter + 1
    Loop
    
    fSize = FileLen(filePath$)
    Counter = 0
    Do While (FileLen(filePath$) = 0 Or FileLen(filePath$) > fSize)
    fSize = FileLen(filePath$)
    If counter > 30 Then
    Exit Function
    End If
    Sleep 1
    counter = counter + 1
    Loop
    
    isFileCreated = True
    
    Exit Function
    ErrorHandler:
    MsgBox GetThreadInfo(1) & " " & Error & " (" & Err & ") op regel " & Erl & "."
    Exit Function
    Resume Next
    End Function
  • Aantal dagen in een bepaalde periode met LotusScript

    Voor een applicatie moest herhaaldelijk uitgerekend worden hoeveel dagen er in een bepaalde periode zitten.
    De volgende functie voldeed hier goed:

    Input: getDaysBetween(“31-12-2007″,”01-01-2007”, “1,7” ,”25/12/07 – 26/12/07,05-12-2007″,Doc)  

    Output: 258

    Function getDaysBetween(strStart As String, strEnd As String,daysToExclude As String , datesToExclude As String ,Doc As NotesDocument) As Long
    On Error GoTo ErrorHandler
    Dim Formula As Variant
    Dim dLow As String
    Dim dHigh As String

    If strStart = “” Or strEnd = “” Then GoTo ErrorHandler

    strStart = {@TextToTime(“} & strStart & {“)}
    strEnd= {@TextToTime(“} & strEnd & {“)}

    If daysToExclude = “” Then
    dLow = {;0}
    Else
    dLow = {;@TextToNumber(@Explode(“} & daysToExclude & {“;”,”))}
    End If

    If Not datesToExclude = “” Then
    dLow = dLow & {;@TextToTime(@Explode(@TextToTime(@Explode(“} & datesToExclude & {“;”,”))))}
    End If

    dHigh$ = {@BusinessDays(} & strStart$ & {;} & strEnd$ & dLow & {)}
    dLow$ = {-@BusinessDays(} & strEnd$ & {;} & strStart$ & dLow & {)}

    Formula = Evaluate({@If(} & strStart & {>} & strEnd & {;} & dLow$ & {;} & dHigh$ & {)} ,Doc)

    getDaysBetween = CLng(Formula(0))

    Exit Function
    ErrorHandler:
    MsgBox GetThreadInfo(1) & ” ” & Error & ” (” & Err & “) op regel ” & Erl & “.”
    getDaysBetween = 0
    Exit Function
    Resume Next
    End Function

  • AddLinkByIds

    Met AddLinkByIds kun je een Weergave of Document koppeling in een RichText veld aanmaken door gebruik te maken van het Replica ID van de doel database en het UNID van de weergave of het document.
    De wel gedocumenteerde AppendDocLink methode heeft echt een Database, Weergave of Document object nodig, deze methode gebruikt dus alleen tekst als parameters.

    AddLinkByIds

    Gedefinieerd in

    NotesRichTextItem

    Syntax

    Call notesRichTextItem.AddLinkByIds( dbReplicaID$, serverHint$, viewUNID$, documentUNID$, comment$ [, HotSpotText$ ])

    Parameters

    serverHint$

    String. Servernaam in Canonical or Common formaat.

    viewUNID$

    String. UniversalID van de weergave. Gebruik een lege string (“”) om een database link te maken of om de “default view” te gebruiken wanneer een document koppeling wordt gebruikt.

    documentUNID$

    String. UniversalID van het document dat je wilt koppelen. Gebruik een lege string (“”) om een weergave of database koppeling te maken.

    comment$

    String. De tekst die verschijnt als de gebruiker de koppeling met de muis selecteert en vast houd (titel of help tekst).

    HotSpotText$

    Optioneel. String. Wanneer opgegeven zal de HotSpotText verschijnen als een informatie blokje met tekst als koppeling, anders wordt de betreffende pictogram afgebeeld (weergave, document of database).

    Tip: het UniversalID van een document is snel te halen uit het Informatievenster van een document.

  • Kleurfuncties zoals RGB en Webkleuren

    Soms is het nodig om kleuren te vertalen naar andere formaten.
    Excel wil bijvoorbeeld graag een RGB kleur als type Long zien, in style sheets e.d. gebruik je de Webkleuren in Hex formaat e.d.
    Meestal gebruik ik het kleurenpallet van Notes om een kleur te bepalen, en gebruik de RGB waarden om verder te werken.

    Een aantal LotusScript functies die ik dan gebruik zijn de volgende:

    Van RGB waarden naar Long (gelijk aan VBA functie, bijv. voor export naar Excel) :

    Function RGB(Byval lRed As Long, Byval lGreen As Long, Byval lBlue As Long) As Long
    ‘input 255,255,255
    Dim tmpLong As Long
    tmpLong = lRed
    tmpLong = tmpLong + (lGreen*256)
    tmpLong = tmpLong + (lBlue*Clng(65536))
    RGB = tmpLong
    ‘Output 16777215
    End Function

    Van HEX naar RGB String (met kleine aanapssing voor bijv. weergavekolommen e.d.) :

    Function HEX2RGB(Byval HexColor As String) As String
    ‘Input #FFFFFF
    HexColor = Replace(HexColor, “#”, “”)
    HEX2RGB = Val(“&H” & Mid(HexColor, 1, 2))  & “,” & Val(“&H” & Mid(HexColor, 3, 2)) & “,” & Val(“&H” & Mid(HexColor, 5, 2))
    ‘Output 255,255,255
    End Function

    Van RGB waarden naar Hex (voor Web, css e.d.):

    Function RGB2HEX(Byval lRed As Long, Byval lGreen As Long, Byval lBlue As Long) As String
    ‘ input 255,255,255
    RGB2HEX = Right(Cstr(Hex(lBlue + 256*(lGreen+256*lRed))),6)
    ‘ Output FFFFFF
    End Function

    RGB kleur naar Notes kleuren (Richtext item e.d.):

    Function RGB2NOTES(Byval lRed As Long, Byval lGreen As Long, Byval lBlue As Long) As Integer
    Dim session As New NotesSession
    Dim color As NotesColorObject
    Set color = session.CreateColorObject
    RGB2NOTES = color.SetRGB(lRed,lGreen,lBlue)
    End Function

  • Weeknummer in Lotusscript

    Weeknummer in Lotusscript

    Voor een applicatie had ik een weeknummer in Lotusscript functie nodig. Format(Now,”ww”) werkt niet goed voor jaren waar een week 53 bestaat.
    Een iets aangepaste script van de MSDN site werkt echter prima.
    Invoer Is een datum, uitvoer Is een tekst met het jaar en het weeknummer waarin de invoerdatum valt.

    Function getWeekNumber(InDate As NotesDateTime) As String
    On Error GoTo ErrorHandler
    Dim DayNo As Integer
    Dim StartDays As Integer
    Dim StopDays As Integer
    Dim StartDay As Integer
    Dim StopDay As Integer
    Dim VNumber As Integer
    Dim ThurFlag As Boolean
    Dim tmpDate As NotesDateTime
    Dim tmpWeek As Integer
    Set tmpDate = New NotesDateTime(DateSerial(Year(inDate.LSLocalTime), 1, 0))
    DayNo = InDate.TimeDifference(tmpDate)/60/60/24
    StartDay = Weekday(DateSerial(Year(InDate.LSLocalTime), 1, 1)) – 1
    StopDay = Weekday(DateSerial(Year(InDate.LSLocalTime ), 12, 31)) – 1
    StartDays = 7 – (StartDay – 1) ‘Number of days for the first calendar week
    StopDays = 7 – (StopDay – 1) ‘Number of days for last calendar week
    If StartDay = 4 Or StopDay = 4 Then ThurFlag = True Else ThurFlag = False ‘Test to see if the year has 53 weeks
    VNumber = (DayNo – StartDays – 4) / 7 ‘If first week has 4 or more days, it will be calendar week 1 otherwise it will belong to last year’s last calendar week
    If StartDays >= 4 Then
    tmpWeek = Fix(VNumber) + 2
    Else
    tmpWeek = Fix(VNumber) + 1
    End If
    If tmpWeek > 52 And ThurFlag = False Then tmpWeek = 1 ‘Handle years whose last days will belong to coming year’s first calendar week
    If tmpWeek = 0 Then ‘Handle years whose first days will belong to the last year’s last calendar week
    Set tmpDate = New NotesDateTime(DateSerial(Year(InDate.LSLocalTime ) – 1, 12, 31))
    getWeekNumber = getWeekNumber(tmpDate) ‘Recursive loop
    Else
    getWeekNumber = Format(inDate.LSLocalTime,”yyyy”) & ” week ” & CStr(tmpWeek)
    End If
    Exit Function
    ErrorHandler:
    MsgBox GetThreadInfo(1) & ” ” & Error & ” (” & Err & “) op regel ” & Erl & “.”
    Exit Function
    Resume Next
    End Function