Thursday, October 4, 2007

@UrlQueryString in Form Formula

I briefly mentioned in my "PHP-like templating in Domino" post, but I think it deserves it's own little tip-post.

You can use @UrlQueryString in form-formula of a view, to decide which form to open a document in.

I may remember wrong, but I think you can do comparison like @UrlQueryString = "print" for "stand-alone" parameters, since @UrlQueryString without a parameter returns a text-list of all request-parameters.

Example of form formula in view, "myview":
@If(
@UrlQueryString = "print" ; "print";
@UrlQueryString = "json" ; "json" ;
@UrlQueryString = "xml" ; "xml" ;
form
)

http://mysite.com/index.nsf/myview/blogpost?OpenDocument
^document is opened in default form

http://mysite.com/index.nsf/myview/blogpost?OpenDocument&print
^form that is printer-friendly

http://mysite.com/index.nsf/myview/blogpost?OpenDocument&json
^form that makes json of data in document

http://mysite.com/index.nsf/myview/blogpost?OpenDocument&xml
^form that makes xml of data in document

These are not Domino-parameters. You have to make the forms yourself.. :)

13 comments:

Sean Burgess said...

Probably one of the most useful @functions for web development. It works great in conjunction with @URLDecode for passing data in valid URLs.

@URLDecode("Domino";@URLQueryString("fromdate"))

Just make sure you encode any attributes that contain ampsands ("&").

Jan Schulz said...

I thought, why all the forms for the content types? and tried to do it with one form and @setHttpHeader... -> replacing that header is not supportet by domino. Oh my, what a pain!

Tommy Valand said...

@Sean:
@UrlQueryString and @WebDbName are probably my most used @-functions.

@UrlEncode also handy when making urls containing urls, e.g.
site := "/thetimes.nsf/news"
"?OpenForm&heading=the+truth";

url := "http://ankhmorpork.com/names.nsf?login"+
"&username=william&password=deworde"+
"&redirectto=" +
@UrlEncode( "iso-8859-1" ; site);

==

@Jan: I feel your pain.. I sometimes wonder why they haven't make every property of forms/page/etc computable at runtime. I shouldn't think it would be that hard.

I also miss the ability to send custom response-headers (e.g. 302 for redirect).

Unknown said...

Nice tip Tommy.

My person preference would be to have a named parameter e.g. type=print, type=json, etc, then use @URLQuerySting("type") to get at the value.

@sean, @URLQueryString decodes the value anyway, so you don't need to do it explicitly. In fact it may cause a double decoding problem if you do.

NotesSensei said...

I would recommend to have a named parameter e.g. "display" so instead of ?OpenView&Json use ?OpenView&display=json. This way it works also when you have additional parameters. SO your form formula would be like that:
curForm := @lowercase(@UrlQueryString("display"));
@if(@isMember(curForm;"json":"print":"xml");curForm;form)

I would go a step further and have forms that are specific: jsonMemo, xmlMemo, printMemo, jsonCalendar, xmlCalendar, printCalendar. Then the statement would be:
@if(@isMember(curForm;"json":"print":"xml");curForm+Form;form)

:-) stw

ANAS MOHAMMED PATLA ABOOBACKER said...

Hi Tommy,

I tried to use Evaluate("@URLQueryString('QueryParamName')")

It always returns null

Does @URLQueryString work in Evaluate

Tommy Valand said...

I haven't tested it, but if you have access to NotesSession.DocumentContext, it might work if you pass that as the second argument in evaluate.

ANAS MOHAMMED PATLA ABOOBACKER said...

I have tried with NotesSession.DocumentContext but it did not work.

Tommy Valand said...

If it's a WebQueryOpen/WebQueryClose agent, NotesSession.DocumentContext represents the document you're working on. To be able to fetch parameters, you could create a computed for display field in the form. In the agent, you can read the value from the field like any other field.

If it's an agent that's opened via a url(?OpenAgent), I wrote a helper class for dealing with those types of situations a while back that might be of some use to you:
HttpRequest Class

ANAS MOHAMMED PATLA ABOOBACKER said...

Yes Tommy, it is an agent that opens via URL. Basically i invoke an agent (via URL) from my Xpage button with two query string parameters. My requirement is to fetch these query string values inside the lotus script agent.

Anonymous said...

there is this url which is causing issue

https://abc.com/xyz.nsf/form.html?open&page=authentication&msg=invalidcredentials">


we are getting relevant data by @urlquerystring("msg")

But now querystring has alert it gives popup on window. I want to get rid of it.

I tried @replace(@right(@urlquerystring("msg"),">");"") but it does not gives relevant data

Anonymous said...

sorry missed full url.

after query string "> is appended.
which is causing alert to prompt.

Anonymous said...

ohh that xss code is not reflecting here in my comments.

so its "> and then alert prompt..