Pass a URL string to a webqueryopen agent?

Is it possible to pass a variable from a URL into a webqueryopen lotusscript agent?  From there I would like to fill in fields on my webdocument.

I currently pass a URL string to a Query_string field and then perform @dblookups based on the Query_string field value but I'm thinking the WebQueryOpen method might be a lot faster.
Who is Participating?
sloeberConnect With a Mentor Commented:
Now, you can capture the Query_String value before the WebQueryOpen.
You must set your Query_String field as computed for display and give it the default value Query_String


Here's another example may be also interesting for you
Put a computed for display field on the form which is displaying your document, containing the folowing formula:
"{<a href=http:/"+@Subset(@DbName;-1)+"/SetFieldAgent?OpenAgent&key="+@Text(@DocumentUniqueID)+">Set Field</a>}"

The agent with the name "SetFieldAgent" has the folowing code:

Sub Initialize
Dim session As New NotesSession
Dim agentdoc As NotesDocument
Dim doc As NotesDocument
Dim db As Notesdatabase
Set db = session.currentdatabase
Set agentdoc = session.DocumentContext
QueryString$ = agentdoc.Query_String(0)
key$ = Mid$(QueryString$,Instr(QueryString$,"key=") + 4)
Set doc = db.GetDocumentByUNID(key$)
doc.Field1 = "Value"
Call, False)
Print "Field value set"
End Sub

try the http_refrer cgi variable, I am not sure if it will work with the webqueryopen agent.

Are you try to pass a variable to the webqueryopen agent when you open the document ?
The best way to do this is by passing arguments to an agent.
The following code can be used in any agent, in to which lots of parameters get passed and place them all in an list.
The agent starts with the standard declarations.

Sub Initialize
Dim s as new notessession
Dim db as notesdocument
dim doc as notesdocument

set db=s.currentdatabase
set doc = s.documentcontext

which are followed by declaring the list variable that will hold all the arguments.

Dim AgentArgs List as string

and now a call to the subroutine that does all the work (appears futher down) :

Call ExplodeQueryString(doc.Query_String(0), AgentArgs)

This list would normally be used to let the agent go and retrieve the required information, but, for the sake of a demo, lets loop through all the parameters and send their key/value pairs back to the browser:

Forall Args in AgentArgs
Print "Parameter Key: " + Listtag(Args)
Print "Parameter Value : " + Args
End Forall
End Sub

This method of looping through ALL the arguments may not be necessary if you already know the name of the parameter's key.
For example, if a key had the name "country", you could get to its value like this :
Print "Country Code: " + AgentArgs("country")

The Explode QueryString() subroutine :

Private Sub ExplodeQueryString(QueryString as string,AgentArgs List as string)
Dim Args as string
Args = StrRight(QueryString,"OpenAgent&",1)

Dim ArgsList as variant
ArgsList = Evaluate({@Explode("}&Args&{";"&")})

Dim ArgKey as string
Dim ArgValue as string

Forall Arg in ArgsList
ArgKey = StrLeft(Arg,"=")
ArgValue = StrRight(Arg,"=")
AgentArgs(ArgKey) = ArgValue
End Forall
End Sub

Overall, not a very good example, but I'll leave it to you as to how you wish to implement it.

PS : Here's an example of what a URL may look like that is used to call a simular agent :

Settings van de agent
Run once from agent list
Run Once(commands may be used)

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

snocrossAuthor Commented:
pcoreyya, yes I want to pass the variable to the WebQueryOpen.

Sloeber, that sounds cool but you are sure the QueryString value will be available to the WebQueryOpen event?  I thought the WebQueryOpen event executed before any fields got filled in.
Have a good weekend Guys !
Hello Sno,

this boys abowe are giving you good examples to experiment around and I recomad you to do so, but here my two pence: the fields are allways calculated wether you call WebQueryOpen or not. The only speedup is that you have less or no field formulas, but field formula recalculation will allways be done. The slowdown is in starting of WebQueryOpen agant. Formulas are allways faster then LotusScript engine initiation. By the way: WebQueryOpen agent can also be formula agents <|;-) and @dblookups are never cached on web :-(
I do offten place the complete code for an agent into one field formula which checks and recalculates other fields. Even the disadvantage that this field is not reusable like an agent is away with using of a shared field. You remember my @dblookup for LDAP? I am doing this corporate directory lookups, without agent, directly in a field on application forms...

Nice weekend,
Jean Marie GeeraertsApplication EngineerCommented:
Hi sno,
Query_String(0) doesn't refer to a field on the form. It refers to the query string defined in the URL used to call the agent. This is everything behind the "&"- in the URL.
For multiple parameters, I'm guessing you can refer to them by seperating them with an "&" and refer to them as Query_String(1), Query_String(2), etc. (I'm nog 100% sure about this, but I can't test it since my test server appears to be down).
My theory is if you call the agent like :
Then :
  Query_String(0) = "par1=yes"
  Query_String(1) = "par2=no"
A way to call the agent like that is to put this javascript-code in the onload-event of the form :
Anyway, test it and let me know if it's working (my test server as I said is acting up today)
snocrossAuthor Commented:
Sloeber, I tried your example but the field just displayed the following...

{<a href=http:/"+@Subset(@DbName;-1)+"/SetFieldAgent?OpenAgent&key="+@Text(@DocumentUniqueID)+">Set Field</a>}

It didn't execute the agent.

Jerrith, your solution looks similar except it's using Javascript... I'll give it a try.

Zvonko, thanks for the interesting info on performance.
Hey Snow,

why do you cut'n paste quirly braces? {}

The correct formula is of corse:
"[<a href=http:/"+@Subset(@DbName;-1)+"/SetFieldAgent?OpenAgent&key="+@Text(@DocumentUniqueID)+">Set Field</a>]"

If you click than on this link, and your SetFieldAgent is some simpler then Sloeber's proposal, like this:
Sub Initialize
  Dim session As New NotesSession
  Dim doc As NotesDocument
  Set doc = session.DocumentContext
  Print "<br>DocId: " & Strright(Ucase(doc.Query_string(0)), "&KEY=")
  Forall item In doc.Items
    Print "<br>" & item.Name & ":<b> " & item.Text & "</b>"
  End Forall
End Sub

Then you get something like this:
DocId: B6A2B971D1CB800EC1256AAC007C1D2D
SERVER_SOFTWARE: Lotus-Domino/5.0.3
SERVER_NAME: localhost
PATH_INFO: /api\oletest.nsf/SetFieldAgent?OpenAgent&key=B6A2B971D1CB800EC1256AAC007C1D2D
QUERY_STRING: OpenAgent&key=B6A2B971D1CB800EC1256AAC007C1D2D
HTTP_ACCEPT_CHARSET: iso-8859-1,*,utf-8
HTTP_ACCEPT: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
HTTP_HOST: localhost
HTTP_USER_AGENT: Mozilla/4.7 [en] (WinNT; I)
HTTP_REFERER: http://localhost/api/oletest.nsf/Show?OpenForm 
QUERY_STRING_DECODED: OpenAgent&key=B6A2B971D1CB800EC1256AAC007C1D2D

Esspecialy look at decoded version of query_string: QUERY_STRING_DECODED

snocrossAuthor Commented:
Thanks to everyone!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.