snocross
asked on
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.
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.
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.Que ry_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(QuerySt ring as string,AgentArgs List as string)
Dim Args as string
Args = StrRight(QueryString,"Open Agent&",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
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.Que
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(QuerySt
Dim Args as string
Args = StrRight(QueryString,"Open
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
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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,
zvonko
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
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=y es&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?O penAgent&p ar1=yes&pa r2=no"
Anyway, test it and let me know if it's working (my test server as I said is acting up today)
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=y
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?O
Anyway, test it and let me know if it's working (my test server as I said is acting up today)
ASKER
Sloeber, I tried your example but the field just displayed the following...
{<a href=http:/"+@Subset(@DbName;-1) +"/SetFiel dAgent?Ope nAgent&key ="+@Text(@ DocumentUn iqueID)+"> 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.
{<a href=http:/"+@Subset(@DbName;-1)
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) +"/SetFiel dAgent?Ope nAgent&key ="+@Text(@ DocumentUn iqueID)+"> 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_s tring(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: B6A2B971D1CB800EC1256AAC00 7C1D2D
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/SetFieldA gent?OpenA gent&key=B 6A2B971D1C B800EC1256 AAC007C1D2 D
PATH_TRANSLATED:
QUERY_STRING: OpenAgent&key=B6A2B971D1CB 800EC1256A AC007C1D2D
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/SetFieldA gent?OpenA gent&key=B 6A2B971D1C B800EC1256 AAC007C1D2 D
QUERY_STRING_DECODED: OpenAgent&key=B6A2B971D1CB 800EC1256A AC007C1D2D
Esspecialy look at decoded version of query_string: QUERY_STRING_DECODED
Regards,
zvonko
why do you cut'n paste quirly braces? {}
The correct formula is of corse:
"[<a href=http:/"+@Subset(@DbName;-1)
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_s
Forall item In doc.Items
Print "<br>" & item.Name & ":<b> " & item.Text & "</b>"
End Forall
End Sub
Then you get something like this:
DocId: B6A2B971D1CB800EC1256AAC00
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/SetFieldA
PATH_TRANSLATED:
QUERY_STRING: OpenAgent&key=B6A2B971D1CB
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/SetFieldA
QUERY_STRING_DECODED: OpenAgent&key=B6A2B971D1CB
Esspecialy look at decoded version of query_string: QUERY_STRING_DECODED
Regards,
zvonko
ASKER
Thanks to everyone!
Are you try to pass a variable to the webqueryopen agent when you open the document ?