Welcome to InteropTips Sign in | Join | Help


Demos

Last post 07-03-2007, 12:04 PM by Goodwin. 1 replies.
Sort Posts: Previous Next
  •  04-11-2006, 5:13 PM 34

    LotusScript Agents that returns formatted XML Notes data using parameters

    Jack Forman took my web agent xml demo and added parameters.  The agent is in the attached database Orders.NSF.   Also attached is a video on how the original Agent was created.

    You can put in any database as long as it is on the same server that the data you are trying to read is on.

    Note: I change the field separator from "&" to "!"  I needed to use the "&" for the search formula.


    The first "&" is needed That is the start of the CGI param
    Both these commands are to the same DB and the same fields.

    This one is a VIEW export the View name is "Customer Orders"  The case does not matter. the space is %20 since that is the name of the view.
    http://www.msdomino.net/orders.nsf/xmlexport?openagent&orders.nsf!view!customer%20orders!shipCountry!orderDate

    So what is happening in this URL call is the first part ("www.msdomino.net/orders.nsf/smlexport?openagent") tell the Domino Server "www.msdomino.net" to execute an Agent called "xmlexport" that is in the database "orders.nsf". the rest of the information is passed to the Agent. "Order.nsf" and "Customer Orders" refers to the View and the Database containing the View. The "shipCountry" and "orderDate" parameters tell the Agent which document item values to return.


    This next one is a Search export. Note that the quotes around the form name is NEEDED and the quotes around the Field value is Needed as it is part of the search formula.  In this agent the case DOES matter. it must match the way the from or field is saved. You can add to the search formula @LOWERCASE or @UPPERCASE I think.
    http://www.msdomino.net/orders.nsf/XMLExport?openagent&orders.nsf!search!form="order"%20&%20ShipCountry="Germany"!shipCountry!orderDate
    Click to watch
    WatchFormat: wmv
    Duration: 8 minutes
  •  07-03-2007, 12:04 PM 126 in reply to 34

    Re: LotusScript Agents that returns formatted XML Notes data using parameters

    This might be of help.

    I've been developing this ongoing since 1999 so it has a few nice refinements. The code is HUGE so although it was very well commented long ago, I eventually had to strip out the comments to fit in the source code editor.

    All I ask is that my name remain on it and that I receive credit for any work done using it.

    Some of the feature;

    1. Can call Urls that Launch other applicatrions installed on the client machine (Word, Excel, etc)
    2. Handles URLs in URLs for portal operations (incluing mixed URL & Var returns).
    3. Allows sending HTTP POST from the server (Useful for Paypal purchase interactions)
    4. Built in Test mode that skips the DocumentContext setting
    5. Automatically detects HTTP POST or GET.
    6. Handles variable passing as &var=data&var=data&var=data
    7. Automatically interprets & Translates all % values in data.
    8. Provides a variable/value return array that can be easily cycled through.

    CHECKCGI(string) is the main call. Make that call with the string and you in TEST mode. Without it, your in live mode and better be calling it with a Web DocumentContext.

    Heres the code.

    Class Web
    'Class Variables that store everything for the web page.
    '    
     Public Head As String
     Public Title As String
     Public Debug As Integer
     Public HTML() As String
     Private Flipper As Integer
     Public PostMethod As String
     Public QueryString As String
     Public Result As Variant
     Public URL As String
     Public Limit As Double
     Public Context As String
     Public UName As String
     Public Tags As Integer
     Public Valid As Integer
     Public Activation As String
     Public ActMsg As String
     
     Sub New()
      Dim Session As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Dim Key1 As String
      Dim Key As String
      
      Limit =1
      Redim HTML(1 To Limit)
      Title=""
      Me.Flipper=1
      Context = "Content-Type:text/html"
      Debug = 0
      Tags = True
      Valid = True
     End Sub
     
     Function ParseChunk(Data As String, Delimiter As String) As Variant
      If Valid Then
       If Debug=1 Then Print "Got to ParseChunk Begin<BR>"
       Dim Begining As Integer
       Dim Ending As Integer
       Dim Current As Integer
       Dim NextPos As Integer
       Dim Piece As String
       Dim Segments() As String
       Current=1
       NextPos=Instr(Current, Data, Delimiter)
       If NextPos>0 Then
        Piece=Mid$(Data, Current, NextPos-Current)
        Redim Preserve Segments(1 To 1)
        Segments(1) = Piece    
        Do While NextPos>0
         Current=NextPos+1
         NextPos=Instr(Current, Data, Delimiter)
         If Len(Data)>=Current Then
          If NextPos=0 Then
           Piece=Mid$(Data, Current, Len(Data)-(Current-1))
           Redim Preserve Segments(1 To Ubound(segments)+1)
           Segments(Ubound(Segments))=Piece
          Else
           Piece=Mid$(Data, Current, NextPos-Current)
           Redim Preserve Segments(1 To Ubound(segments)+1)
           Segments(Ubound(Segments))=Piece
          End If
         End If
        Loop
        ParseChunk=Segments
       Else
        ParseChunk = Data
       End If
       If Debug=1 Then Print "Got to ParseChunk End<BR>"  
      End If
     End Function 
     
     Sub StoreHTML(HTMLLine As String)
      If Valid Then
       If Debug=1 Then Print "Got to StoreHTML Begin<BR>"
       Limit = Ubound(HTML)
       If Len(HTML(Limit))>30000 Then
        Limit = Limit +1
        Redim Preserve HTML(1 To Limit)
       End If
       HTML(Limit) = HTML(Limit) + HTMLLine + Chr$(13)
       If Debug=1 Then Print "Got to StoreHTML End<BR>"
      End If
     End Sub    
     
     Sub FormatHTML(Info As Variant, PrintType As String)
      Dim Index As Integer
      Dim HTMLLine As String
      
      
      If PrintType = "Heading" Then
       HTMLLine = HTMLLine+|<TR bgcolor="#ffcc00">|
      Else
       If Me.Flipper=1 Then 
        HTMLLine = HTMLLine+|<TR bgcolor="#ffff99">|
        Me.Flipper = 0
       Else
        HTMLLine = HTMLLine+|<TR bgcolor="#ffffff">|
        Me.Flipper = 1
       End If
      End If
      
      For Index = Lbound(Info) To Ubound(Info)
       If PrintType="Heading" Then
        HTMLLine = HTMLLine+|<TD><B>| & Info(Index) & |</B></TD>| & Chr$(13)
       Else
        HTMLLine = HTMLLine+|<TD>| & Info(Index) & |</TD>| & Chr$(13)
       End If
      Next
      HTMLLine = HTMLLine+|</TR>|
      Me.StoreHTML(HTMLLine)
     End Sub    
     
     Sub PrintHTML()
      If Valid Then
       If Debug=1 Then Print "Got to PrintHTML Begin<BR>"
       Dim session As New NotesSession
       Dim Index As Integer
       Print Context
       Print |<HTML>|
       Print |<!-- John Goodwin's Web Class - Simply the Best Domino tools on the web! -->|
       If Tags Then Print |<Title>| & Title & |</Title>|
       If Head<>"" Then
        If Tags Then Print |<Head>|
        Print Head
        If Tags Then Print |</Head>|
       End If
       If Tags Then Print |<Body>|
       For Index = 1 To Limit
        Print HTML(Index)
       Next
       If Tags Then Print |</Body>|
       Print |</HTML>|
       If Debug=1 Then Print "Got to PrintHTML End<BR>"
      End If
     End Sub    
     
     
     Property Set ContentType As String
      If Valid Then
       Select Case Ucase(ContentType)
       Case "EXCEL"
        Context = "Content-Type:application/vnd.ms-excel"
       Case "HTML"
        Context = "Content-Type:text/html"
       Case "WORD"
        Context = "Content-Type:application/msword"  
       Case "TEXT"
        Context = "Content-Type:text/richtext"
       Case "PDF"
        Context = "Content-Type:application/x-pdf"
       Case "POST"
        Context = "Content-Type:application/x-www-form-urlencoded"
       End Select
      End If
     End Property
     
     
     Property Set WebUserName As String 
      If Valid Then
       Me.UName = WebUserName
      End If
     End Property
     
     Property Get WebUserName As String
      If Valid Then
       Dim UserName As New NotesName(Me.UName)
       WebUserName = UserName.Common
      End If
     End Property
     
     Property Set AutoTags As Integer
      If Valid Then
       If AutoTags Then
        Me.Tags = True
       Else
        Me.Tags = False
       End If
      End If
     End Property
     
     Property Get AutoTags As Integer
      If Valid Then
       AutoTags = Tags
      End If
     End Property
     
     Property Get Method As String
      Method = Me.PostMethod
     End Property
     
     Function ParseResult(Value As String) As Variant
      If Valid Then
       If Debug=1 Then Print "Got to ParseResult Begin<BR>"
       Dim ParmBeginPos As Integer
       Dim ParmEndPos As Integer
       Dim AnswerBeginPos As Integer
       Dim AnswerEndPos As Integer
       Dim Index As Integer
       Dim Parsed() As String
       Dim Counter As Integer
       Dim Skip As Integer
       
       Skip = 0
       If PostMethod="Get" Then
        Counter = 0 ' Changed to 0 for URL results ************************************************************************************************************
       Else
        Counter = 1
       End If
       Pos=0
       For Index = 1 To Len(Value)
        If Mid$(Value,Index,1)=Chr(34) Then
         If Skip = 0 Then Skip = -1 Else Skip = 0
        End If
        If Not Skip Then
         If Mid$(Value,Index,1)="&" Then
          Counter=Counter+1
         End If
        End If
       Next
       If PostMethod="Get" Then
        Value = Right(Value, Len(Value)-1)
       End If
       Redim Parsed(1 To Counter, 1 To 2)
       For Index= 1 To counter
        If Index=1 Then
         ParmBeginPos=1
         ParmEndPos=Instr(ParmBeginPos,Value,"=")
         AnswerBeginPos=ParmEndPos+1
         AnswerEndPos=Instr(AnswerBeginPos,Value,"&")
         If AnswerEndPos = 0 Then
          AnswerEndPos = Len(Value)+1
         End If
         If Instr(AnswerBeginPos, Value, Chr$(34))<AnswerEndPos  And Instr(AnswerBeginPos, Value, Chr$(34))>0Then
          AnswerBeginPos=ParmEndPos+1
          AnswerEndPos=Instr(AnswerBeginPos+1,Value,Chr$(34))+1
         End If
        Elseif Index=counter Then
         ParmBeginPos=AnswerEndPos+1
         ParmEndPos=Instr(ParmBeginPos,Value,"=")
         AnswerBeginPos=ParmEndPos+1
         AnswerEndPos=Len(Value)+1
         If Instr(AnswerBeginPos, Value, Chr$(34))<AnswerEndPos  And Instr(AnswerBeginPos, Value, Chr$(34))>0 Then
          AnswerBeginPos=ParmEndPos+1
          AnswerEndPos=Instr(AnswerBeginPos+1,Value,Chr$(34))+1
         End If
        Else
         ParmBeginPos=AnswerEndPos+1
         ParmEndPos=Instr(ParmBeginPos,Value,"=")
         AnswerBeginPos=ParmEndPos+1
         AnswerEndPos=Instr(AnswerBeginPos,Value,"&")
         If Instr(AnswerBeginPos, Value, Chr$(34))<AnswerEndPos And Instr(AnswerBeginPos, Value, Chr$(34))>0Then
          AnswerBeginPos=ParmEndPos+1
          AnswerEndPos=Instr(AnswerBeginPos+1,Value,Chr$(34))+1
         End If
        End If
        If ParmEndPos = 0 Then
         Parsed(Index,1)=Mid$(Value,ParmBeginPos,ParmBeginPos)
         Parsed(Index,2)=Mid$(Value,AnswerBeginPos,AnswerEndPos-AnswerBeginPos)
        Else
         Parsed(Index,1)=Mid$(Value,ParmBeginPos,ParmEndPos-ParmBeginPos)
         Parsed(Index,2)=Mid$(Value,AnswerBeginPos,AnswerEndPos-AnswerBeginPos)
        End If
       Next
       ParseResult = Parsed
       If Debug=1 Then Print "Got to ParseResult End<BR>"
      End If
     End Function
     
     Function ParseHex(Value As String) As String
      If Valid Then
       If Debug=1 Then Print "Got to ParseHex Begin<BR>"
       Dim Parsed As String
       Dim Index3 As Integer
       For Index3 = 1 To Len(Value)
        If Mid(Value,Index3,1)="%" Then
         Character = Val("&H"+Mid(Value,Index3+1,2))
         Parsed=Left$(Parsed,Index3-1)+Chr(Character)
         index3=index3+2
        Else
         Parsed=Parsed+Mid(Value,Index3,1)
        End If
       Next
       ParseHex=Parsed
       If Debug=1 Then Print "Got to ParseHex End<BR>"
      End If
     End Function
     
     Function ParseAmpersands(QueryString As String) As Variant
      If Valid Then
       If Debug=1 Then Print "Got to ParseAmpersand Begin<BR>"
       Dim Session As New NotesSession
       Dim db As NotesDatabase
       Dim doc As NotesDocument
       
       Dim index As Integer
       Dim Index2 As Integer
       Dim Index3 As Integer
       Dim Parse() As String
       Dim Ampersands() As Integer
       Dim POS As Integer
       Dim Counter As Integer
       
       Set db = session.CurrentDatabase
       Set doc = session.documentcontext
       
       If Instr(1,QueryString, "&")>0 Then
        Redim Ampersands(0)
        Counter=0
        Do
         Pos = Instr(POS+1,QueryString, "&")
         If Pos>0 Then
          Ampersands(Counter)=POS
          If Instr(POS+1,QueryString, "&") Then
           Counter=Counter+1
           Redim Preserve Ampersands(counter)
          End If
         End If
        Loop While POS>0
        
        For Index=0 To Ubound(Ampersands)
         Redim Preserve Parse(Index)
         If Index=Ubound(Ampersands) Then
          Parse(Index)=Mid$(QueryString, Ampersands(Index)+1, (Len(QueryString)-Ampersands(Index))+1)
         Else
          Parse(Index)=Mid$(QueryString, Ampersands(Index)+1, (Ampersands(Index+1)-Ampersands(Index))-1)
         End If
        Next
       Else
        Redim Parse(0)
        Parse(0)=""
        Msgbox "Parsed(0) cleaned out"
       End If
       ParseAmpersands=Parse
       If Debug=1 Then Print "Got to ParseAmpersand End<BR>"  
      End If
     End Function         
     
     
     Function ParseReplace(Value As String, Hunt As String, MyReplace As String) As String
      If Valid Then
       If Debug=1 Then Print "Got to ParseReplace Begin<BR>"
       Dim Parsed As String
       Dim Index As Integer
       Parsed=""
       For Index = 1 To Len(Value)
        If Mid$(Value,Index,1)=Hunt Then
         Parsed = Parsed +MyReplace
        Else
         Parsed = Parsed + Mid$(Value,Index,1)
        End If
       Next
       ParseReplace=Parsed
       If Debug=1 Then Print "Got to ParseReplace End<BR>"
      End If
     End Function
     
     Function CheckCGI(TestData As String) As Variant
      If Valid Then
       If Debug=1 Then Print "Got to CheckCGI Begin<BR>"
       Dim session As New NotesSession
       Dim Doc As NotesDocument
       Dim Flag As Integer
       Dim index As Integer
       Dim Pos As Integer
       Dim InetType As String
       Dim HasInfo As Integer
       Flag=0
       INetType="TEST"
       
       If testData="" Then
        Set Doc = Session.DocumentContext
        Forall itm In Doc.Items
         If itm.name="REQUEST_CONTENT" Then
          Flag=1
          INetType = "FORM"
         End If
        End Forall
       End If
       
       If TestData = ""  And Flag = 0 Then
        INetType = "URL"
       End If
       
       Select Case INetType
       Case "FORM"
        If Debug=1 Then Print "Got to CheckCGI Form Begin<BR>"
        QueryString = Session.DocumentContext.Request_Content(0)
        URL = Session.DocumentContext.Query_String(0)
        Me.WebUserName = Session.DocumentContext.Remote_User(0)
        HasInfo = 1
        PostMethod="Post"   
        
       Case "URL"
        If Debug=1 Then Print "Got to CheckCGI URL Begin<BR>"
        QueryString=Session.DocumentContext.Query_String(0)
        Pos = Instr(1, QueryString, "&")
        HasInfo = Pos
        QueryString = Right(QueryString, (Len(QueryString)-(Pos-1)))
        Me.WebUserName = Session.DocumentContext.Remote_User(0)
        PostMethod="Get"
        
       Case "TEST"
        If Debug=1 Then Print "Got to CheckCGI TEST Begin<BR>"
        QueryString = TestData
        Pos = Instr(1, QueryString, "&")
        HasInfo = Pos
        QueryString = Right(QueryString, (Len(QueryString)-(Pos-1)))
        PostMethod="Get"
       End Select
       
       If  HasInfo Then
        If PostMethod ="Post" Then
         Result = Me.ParseResult(QueryString)
        Else
         Result = Me.ParseResult(QueryString)
        End If
        
        For Index = Lbound(Result) To Ubound(Result)
         Result(Index,2) = Me.ParseReplace(Result(Index,2), "+", " ")
         Result(Index,2) = Me.ParseHex(Result(Index,2))
        Next
       Else
        Dim DataError() As String
        Redim DataError(1 To 1, 1 To 1)
        DataError(1,1) = "No Data"
        Result=DataError
       End If
       CheckCGI=Result
       If Debug=1 Then Print "Got to CheckCGI End<BR>"
      Else
       CheckCGI = ActMsg
      End If
     End Function
     
     
     Function CheckURL() As Variant
      If Valid Then
       If Debug=1 Then Print "Got to GetURL Begin<BR>"
       Dim Index As Integer
       
       QueryString=URL
       Pos = Instr(1, QueryString, "&")
       QueryString = Right(QueryString, (Len(QueryString)-(Pos-1)))
       Me.PostMethod="Get"
       
       Result = Me.ParseResult(QueryString)
       For Index = Lbound(Result) To Ubound(Result)
        Result(Index,2) = Me.ParseReplace(Result(Index,2), "+", " ")
        Result(Index,2) = Me.ParseHex(Result(Index,2))
       Next
       Me.PostMethod="Post"
       CheckURL=Result
       If Debug=1 Then Print "Got to GetURL End<BR>"
      End If
     End Function
     

    End Class

     

     

     

View as RSS news feed in XML

Terms of Use |  Upload Agreement |  Trademarks |  Privacy Statement |  Contact Us

© 2006 Microsoft Corporation. All rights reserved.