Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1985
  • Last Modified:

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.
0
snocross
Asked:
snocross
  • 3
  • 2
  • 2
  • +3
1 Solution
 
pcorreyaCommented:
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 ?
0
 
sloeberCommented:
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 :
//www.domain.com/website.nsf/report?OpenAgent&country=be&name=sloeber&date=21%2F11%2F2000

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


Greets,
Sloeber
0
 
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sloeberCommented:
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

Greets,
Sloeber

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 doc.save(True, False)
Print "Field value set"
End Sub


Greets,
Sloeber
0
 
ArunkumarCommented:
Have a good weekend Guys !
0
 
zvonkoCommented:
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,
zvonko
0
 
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 :
agentName?OpenAgent&par1=yes&par2=no
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 :
location.href="agentNmae?OpenAgent&par1=yes&par2=no"
Anyway, test it and let me know if it's working (my test server as I said is acting up today)
0
 
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.
0
 
zvonkoCommented:
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
SERVER_PORT: 80
SERVER_PROTOCOL: HTTP/1.0
REQUEST_METHOD: GET
PATH_INFO: /api\oletest.nsf/SetFieldAgent?OpenAgent&key=B6A2B971D1CB800EC1256AAC007C1D2D
PATH_TRANSLATED:
QUERY_STRING: OpenAgent&key=B6A2B971D1CB800EC1256AAC007C1D2D
REMOTE_ADDR: 127.0.0.1
AUTH_TYPE:
REMOTE_USER:
REMOTE_IDENT:
HTTPS_KEYSIZE:
HTTPS: OFF
HTTP_ACCEPT_CHARSET: iso-8859-1,*,utf-8
HTTP_ACCEPT_LANGUAGE: en
HTTP_ACCEPT_ENCODING: gzip
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_CONNECTION: Keep-Alive
HTTP_REFERER: http://localhost/api/oletest.nsf/Show?OpenForm 
PATH_INFO_DECODED:
/api\oletest.nsf/SetFieldAgent?OpenAgent&key=B6A2B971D1CB800EC1256AAC007C1D2D
QUERY_STRING_DECODED: OpenAgent&key=B6A2B971D1CB800EC1256AAC007C1D2D

Esspecialy look at decoded version of query_string: QUERY_STRING_DECODED

Regards,
zvonko
0
 
snocrossAuthor Commented:
Thanks to everyone!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now