PermaLinkBigBill's Big 7, number 105/04/2005 07:13:16 AM
Written By : Scott Good

In honor of Bill Ernest (see the post below), beginning today and for the next week I'm going to post each day one of the truly cool things you can do with Notes (and/or Domino) based on things Bill figured out. So, here goes:

#1: Building dynamic JavaScript in a WebQuerySave agent.

If you build web applications involving any sophistication, pretty soon you get to the point where simply submitting a document and diverting to a URL specified in the $$Return field is not enough. For instance, what you probably want to do is return to the view you came from when you first opened the document, just like you would if you were using the Notes client.

The problem is, how do you do that?

At first, it seems like an easy question. You know the name of the view, just put it in the $$Return and be done with it. But that doesn't really work, for a couple of reasons. First, $$Return can take you back to a view but it might not be the right view. If it is the right view (whether by application of your fine development skills or just plain old good luck), chances are it's not in the right part of the view.

The issue, in most cases, is that you usually have to navigate around in a view for a while to get to the document you care about. You may go down a few pages then expand a couple of categories to get to it. At that point, you're at a very specific URL. While you may have started at a URL like this:

http://YourServer/YourDb.nsf/AllDocsByType?OpenView

Where you ended up is a place with a URL more like this:

http://YourServer/YourDb.nsf/AllDocsByType?OpenView&Start=148&Count=50&Expand=180.1#180.1

Writing a little formula in the $$Return field to simply come back to the view will bring you back to the top of the view, not the place you worked so hard to get to. If you're doing a bit of work on several related documents located some number of pages down into your site, this can be incredibly frustrating.

So, you have to ask yourself at some point, what can I do to make that better?

Well, I'm glad you asked. Really. I am.

$$Return, while handy enough in low-use or very simple applications is a weak substitute for a real solution ("I pity the fool...."). What you need here is real code you can control in a useful way. What you need is some JavaScript in a WebQuerySave agent.

"JavaScript?," you say. "I can't use JavaScript in a WebQuerySave agent," you say. "Notes agents only let you write code in @Formulas, LotusScript and Java. You can't do JavaScript in a Notes agent," you say.

"Hahahahahaha," I say. "You didn't know Bill! He didn't always follow the rules. He found ways around them. You can write all the JavaScript you want in a WebQuerySave agent." And then, I show you:

LotusScript Print statements are the key

In a LotusScript agent that runs in the UI, you probably already know that if you use Print statements...

Print "Updating document #" + Cstr(i)

...the string you provide will be written to the status bar at the bottom of Notes client window. It's a handy way of, for instance, letting the user know his computer hasn't died a quiet death while running a long process.

That same Print statement, used in a Notes background agent, writes information to the Notes Log. This can be used both to totally piss off your Notes administrators and to give yourself or others important information about the status of an agent or related process.

You probably knew both those things. What you may not have known is that the lowly Print statement, when used in a WebQuerySave agent, writes whatever string(s) you provide directly to the browser, with no filtering, as Pass-Thru HTML.

Oooooooo.

And, if you write the code inside <script> tags, you can write JavaScript straight to the browser.

Oooooooo, too.

So, to be able to get back to exactly the place you came from in a view, how would you do it? The first problem is knowing where you were. One approach, which we've used in ProcessIt! is to pass the view location through into the document in the Query_String, parse it out, manipulate as necessary, and use it as we see fit. That works quite well, but it's a bit fussy to get right and requires all the views to play along. Not for the timid.

A simpler approach is to store the data in a separate frame. If you're using framesets, this is easy. If you're not, you could consider adding a hidden frame to your page for this purpose. The idea is this: create a JavaScript variable, let's call it currentViewLocation, on the page in the extra frame. It might be the page you have a navigator on, for instance.

Then, on your $$ViewTemplate form (oh, please tell me you're not just showing people views the way Notes serves them up!), add a quick JavaScript function to the onLoad event to write the page's current location to the frame's JavaScript variable (you can get it from the CGI variable "Path_Info_Decoded" by placing a field of that name on your form):

if (window.parent.parent.left){
     window.parent.parent.left.currentViewLocation = document.forms[0].Path_Info_Decoded.value;
}

Every time you change the view URL by moving to the next page or expanding or collapsing the twisties, the $$ViewTemplate will reload, run the onLoad event, and update the currentViewLocation value in the outside frame. Now you just need to use it.

In your WebQuerySave agent, do whatever else you need to do, but at the end, add this:

Print |<script type="text/javascript">|
Print |   window.location = window.parent.parent.left.currentViewLocation;|
Print |</script>|

That's all there is to it! Of course, once you've figured out you can write a little JavaScript to the browser like this, pretty soon you start writing a LOT of it and doing much more sophisticated things. But, I'll leave that to you to figure out.

See you tomorrow.


Commentsv

1. Richard Schwartz05/04/2005 11:58:11 AM
Homepage: http://smokey.rhs.com/web/blog/PowerOfTheSchwartz.nsf


Wonderful idea, and great tip, too, Scott. I think this is a fitting tribute to a great guy who has helped so many people over the years. Over in my blog I'm also suggesting http://smokey.rhs.com/web/blog/PowerOfTheSchwartz.nsf/d6plinks/RSCZ-6C3LBG that other people add to this tribute by posting their own tips this week in honor of Bill.

-rich




2. Ashish Sidapara05/04/2005 09:41:02 PM
Homepage: http://lono.blogspirit.com


Appreciate your idea Scott !
The Notes community owes him alot and this is one of the best ways to give it back.




3. Carolyn Kraut05/16/2005 10:17:51 AM
Homepage: http://panther.sharedknowledgesystems.com:81/sksblog.nsf


This is an interesting approach that I will have to try. Up until now I have been using a cookie/$$Return formula combination. I've been lucky in that my customers have been okay about allowing cookies for my applications but I'm sure there will come a time when objections will be raised.




4. Hannes11/19/2007 07:12:47 AM


Hi guys, this is great but I have a question and maybe you help me out! I have been stuck on this for 2 weeks now and I just can't think of any way to do this, I have an application that draws forms based on the users requirements. This is a HTML page with fields, dropdowns, radio buttons etc.
Basically a generic questionare whith the whole page build up using Lotus Script Print statements. This all works great but I would like to generate a document from this form with field values same as the values captured on the form.

I can create the whole form with input fields and submit buttons with Javascript field validations, but I cant create a document with the values as inserted on the form by another user. The problem is that the print statements doesn't generate a new document.

Any Idaes I am really stuck.

Much appreciated!




5. Newbs11/19/2007 09:39:07 AM
Homepage: http://www.henrynewberry.com


@Hannes:

What you need to do is submit the form to another agent that has the smarts to extract the data and create the document. In the <Form> tag you add a parameter called action which you then point at your agent. Include in the agent url parameters that tells you what form you are using so you can easily validate the items that are being sent.

The agent will need to parse out the items from the CGI Variable Query_String_Decoded and REQUEST_CONTENT.

There are examples in this session from Advisor Live 2005. http://www.henrynewberry.com/newbs/website2.nsf/DocsByKey/HNEY6EGSHA?opendocument

Let em know if this helps.

Newbs




6. Scott Good11/19/2007 09:46:25 AM
Homepage: http://www.scottgood.com


@Hannes,

In case you haven't figured it out already, Henry Newberry is the new Bill Ernest (at least as far as we're concerned).

Scott




Enter Comments^



Email addresses provided are not made available on this site.





You can use UUB Code in your posts.

[b]bold[/b]  [i]italic[/i]  [u]underline[/u]  [s]strikethrough[/s]

URL's will be automatically converted to Links


:-) :cry: :-\ :huh: ;-) :cool: :grin: :emb: :laugh: :-p :lips: :-( :rolleyes: :-o :-D :angry: :-x






Remember me    

Disclaimer & Copyright
Monthly Archive
Contact me...

or IM: JSG1901
SMRT Racing Team

Thank you sponsors!

Infinite Fiberworks Co, a great source for high-quality Porsche fiberglass parts

Infinite Fiberworks Co.

If you are looking for fiberglass for Porsches, IFC is the place to go. I have used parts from most of the major suppliers and IFC's are easily the highest quality and the most reasonably-priced. Contact Mike at Infinite Fiberworks for more information.

Located in Racine, OH (so far Southeast they're almost in West Virginia), IFC's goal is to be The Best. Give 'em a try.


Bent or ugly wheels? Call Wheel Medic!

Wheel Medic & The Round House

Whether you need to repair, repaint, refinish or just replace your wheels, the guys at Wheel Medic/Round House can get you back on the road in no time!

Wheel Medic, Inc is a family-owned company which specializes in the repair and restoration of aluminum wheels.

The Round House was founded to service Wheel Medic's clients looking for more than just repair work...from custom wheel colors to high-end wheel applications and body kits, the Round House is there to serve the discriminating automotive enthusiast.


Used Porsche parts, great prices!

A Part Above

Looking for used parts for 944s, 924s, 968s or other late-model water-cooled Porsches? Contact John at A Part Above.

Located in Strongsville, OH (20 miles south of Cleveland) their goal is to provide top quality parts and services. I can tell you, John is great to work with and the prices? Very hard to beat.


SMRT Motorsports wants you!

SMRT (that's short for Skid Mark Racing Team), a very-

loosely organized band of fun-loving friends who enjoy auto racing (heck, cars in general), and the occasional adult beverage, wants you to be a part of our team.

Go here to find cool T-shirts, sweatshirts, caps and mugs with the SMRT team logo.

The BlogRoll
Lotus Domino ND6 RSS News Feed RSS Comments Feed Geo URL RSS Validator Blog Admin Lotus Geek Open Notes Picture Database OpenNTF BlogSphere
Calendar
March 2010
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
By Category
What I do for a living


I am the President of Teamwork Solutions a long-time Lotus, now IBM, Premier Partner.

With offices in Columbus and Cincinnati, Ohio, we specialize in custom application development for IBM Lotus Notes, Domino, and related technologies. Our software product, ProcessIt! (see below), is quite possibly the world's best, most powerful and easiest-to-use workflow tool for Notes and the web.

Our clients are some of the world's largest corporations along with others that aren't so big.

We do excellent work, quickly, and often on a fixed-fee basis. We'd love to talk to you about your next project.




I am a Contributing Author to Lotus Advisor Magazine, with more than 40 articles under my belt.

I've written how-to series (serieses?) on LotusScript, JavaScript, Cascading Style Sheets (CSS), and now, AJAX (Asynchronous JavaScript and XML), as well as a bit on miscellaneous web development topics.


TheView.jpg

I also write for The View as of the July/August issue where I showed how to take an ugly Notes applications and make it beautiful with just a few minutes' (careful) work.



I am the chief architect and one of two primary developers for what many consider the best all-around workflow tool for Notes/Domino, anywhere, regardless of price.

It's called ProcessIt!, and you can read all about it at www.notesworkflow.com but the bottom line is this: ProcessIt! is fast and easy to learn, extremely powerful, and can be used by mortals. Even--dare I say it?--common users.

You can spend a lot more on a workflow tool but you won't be able to do a lot more for all the extra money.

Don't believe me? Download and try it for free for 60 days.



GTSLogoSm.gif
Copyright Porsche and NASA...not me!

I race a Porsche 944 S2 in National Auto Sport Assocation events and am the 2008 National Champion in NASA's GTS2 class.

Blame this event, a few years ago, for starting that particular money drain all over again.

In support of my habit, I am the NASA Great Lakes Region's GTS (German Touring Series) Director.

I'm also a Nationally-Certified Instructor for the Porsche Club of America and am in charge of classroom sessions for the Mid-Ohio region when we are doing high performance driving events.

In a prior racing life, I was the Midwestern Regional Formula Atlantic Champion and, in 1991, the Ohio Vally Region of SCCA's Regional Driver of the Year (but that, alas, went away when my credit cards let go of the rope!).




I'm writing a book...or at least trying to.

It's murder mystery in which, not too surprisingly, the main character runs a small software company and races cars for fun. Oh yeah, and lives near where I do.

Just where do they come up with these crazy ideas?

Facebook