• Browse Blogs
  • My Blog
  • My Updates

+Tags Get help with tags?

  • View as cloud  | list

+ Similar Entries

photo

Bringing The Power O...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     No CommentsComments 0
photo

8.5.1 UNFAIL - Part ...

Blog:  Erik Brooks
Erik Brooks
Updated 
RatingsRatings 2     No CommentsComments 0
photo

8.5.1 FAIL. Your cod...

Blog:  Erik Brooks
Erik Brooks
Updated 
RatingsRatings 6     CommentsComments 29
photo

Domino on the Web? Y...

Blog:  Erik Brooks
Erik Brooks
Updated 
No RatingsRatings 0     CommentsComments 2
photo

uidoc.gotoField gotc...

Blog:  Patrick Picar...
Patrick Picard
Updated 
No RatingsRatings 0     No CommentsComments 0

+ Blog Authors  

Parse URL in Domino agent

Karl-Henry Martinsson |   | Tags:  web code_snippet programming lotusscript | Comments (3)  |  Visits (1,179)

Not Forum Friday, but Usenet Tuesday. :-)  A user in comp.groupware.lotus-notes.programmer had a question about generating Notes document remotely/in an automated way from another web application, using Perl:

 

> We have a Lotus Notes application and we would like to automate
> creating a new document or record in that application from another web
> based application.
>
> Here are the details:
> User action on web application triggers a PERL script to create a new
> record (document) in Lotus Notes (or Domino).

 

Here is my suggestion:

 

Create an agent that read the URL parameters you send to it.
Let's call the agent CreateNewDocument, and have two fields we want to fill out when the document is created. The Perl script can then call the URL like this:
 
 
The agent read the arguments and populate the corresponding fields, then save the document. I would highly recommend using a list to store the parameters, then you have a generic function you can re-use in any application.
In my article in the November/December 2006 issue of The View (starting on page 25) you have code for this.
 
Here is a class I just wrote to parse an incoming HTTP GET or POST. Put it in a script library called for example "URL.class":
 
Class URLclass
Public url As String
Private params List As String

Public Sub New()
  Dim session As New NotesSession
  Dim doc As NotesDocument
  Set doc = session.DocumentContext ' Document with all CGI variables
  ' Check if HTTP GET or POST was used...
  If Instr(doc.Query_String(0),"&") > 0 Then  ' GET was used
   url = doc.Query_String(0) 
  Elseif Instr(doc.Request_Content(0),"&") > 0 Then ' POST was used
   url = "&" & doc.Request_Content(0)
  Else          ' No parameters
   Exit Sub
  End If
End Sub

Public Function GetParams() As Variant
  Dim offset As Integer
  Dim startpos As Integer
  Dim midpos As Integer
  Dim endpos As Integer
  Dim nextpos As Integer
  Dim dataname As String
  Dim datavalue As String
  startpos = Instr(url,"&")    ' Start of first parameter
  Do While Not startpos = 0
   nextpos = Instr(startpos+1, url, "&") ' Start of next parameter
   If nextpos = 0 Then     ' We reached the end
    endpos = Len(url)+1
   Else
    endpos = nextpos
   End If
   midpos = Instr(startpos+1, url, "=") ' Position of = character
   dataname = Mid$(url,startpos+1,midpos-startpos-1)  ' Get name
   datavalue = Mid$(url,midpos+1,endpos-midpos-1)  ' Get value
   params(dataname) = datavalue   ' Add value to list
   startpos = nextpos     ' Set new start position
  Loop
  GetParams = params
End Function

End Class
 

Here is a sample agent that uses the class and print the arguments to the browser. Just expand on that code to create the document in the database:

 

Option Public
Option Declare
Use
"URL.class"
 

Sub Initialize
 Dim url As New URLclass

 Dim params As Variant
 params = url.GetParams()
 Forall x In params
   Print Listtag(x) & " = " & params(Listtag(x)) & "<br>"
 End Forall
End Sub

 

The LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
No RatingsRatings 0

Comments (3)

photo
1 Tim Tripcony commented   Permalink No RatingsRatings 0

If the Perl script issues a POST request instead of a GET, you can do this without an agent:

http://www.example.com/notesdd.nsf/FormName?CreateDocument

That way you can just post the field/value pairs and they'll be written to the correct fields automatically. It'll also honor any WebQuerySave agents defined on the form, $$Return, input validations, etc.

photo
2 Steve McDonagh commented   Permalink No RatingsRatings 0

Karl-Henry

Great minds think alike :-)
I posted on this very topic a few days ago except I took a slightly different approach. here

I like your idea of the class for the wrapper can I use your code with mine?

Steve

photo
3 Karl-Henry Martinsson commented   Permalink No RatingsRatings 0

@Steve: Of course, go ahead and use any code you like. I looked at your code, it looks good. I try to avoid using evaluate(), not because of any particular good reason, I just don't like to mix languages. Also, all my code is written for R5, so I don't have Split() (or @URLDecode).
I also wrote my my code to handle both GET and POST, where the data lives in Request_Content and Query_String (or Query_String_Decoded) depending on what call is being made.

@Tim: Very true. Did not think about that. Usually because I most of the time do more in my web agents than just create a document.

Add a Comment Add a Comment

Previous |  Main  | Next
Skip to main content link. Accesskey S
IBM Lotus Connections Help Tools About