Web vs client

Hi,

with help from members of this forum I have created this piece of code that is in agent which is triggered by a button and should work on the web. But nothing hapens when i run it on IE it does work on Notes client.

Can Lotusscript code be run at all on web.

Please help

Thank you

Sub Initialize

Dim ws As New NotesUIWorkspace

Dim doc As NotesUIDocument

Dim s As New notessession

Dim db As notesdatabase

Dim vw As notesview

Dim curdoc As notesdocument

Dim vwdoc As notesdocument



Set doc = ws.CurrentDocument



Set db = s.GetDatabase("MyServer","mybase.nsf")

If db Is Nothing Then

	Messagebox "Nemogu pristupiti bazi podataka" ,, "Greška!"

	Exit Sub

End If

Set vw = db.getview("WICRnlg") 

If vw Is Nothing Then

	Messagebox "Nemogu pristupiti radnim nalozima" ,, "Greška!"

	Exit Sub

End If









If doc.Document.BrjRnlg(0) = "" Then Exit Sub



Set vwdoc = vw.getdocumentbykey(doc.Document.BrjRnlg(0))

If vwdoc Is Nothing Then

	Messagebox "Nemogu pronaci radni nalog s tim brojem" ,, "Greška!"

	Exit Sub

End If

doc.EditMode = True

Call doc.FieldSetText("BrjUgvr",vwdoc.doc_broj(0))

Call doc.FieldSetText("UsrNm",usrnm)

Call doc.FieldSetText("BrjUgvr",pswrd)

End Sub

Subject: a host of questions

Brane,

Are there other fields that the user will be editing on that document?

Does the user need to be able to edit these fields you’re pulling up?

Answering those questions will help determine how to proceed. Several options appear going forward, based on those:

It may simply involve opening a new browser window based on user choices in the original window.

It might involve passing values via a URL to the agent (using Query Strings).

It could use a Javascript-based “dbLookup” to find the values.

Or… maybe it could involve AJAX (Asynchronous Javascript and XML), which is one of the hot things in use now.

Awaiting answers…

Dave Navarre

Chub Toad

Subject: RE: a host of questions

Hi Dave and hi Chub,

There is one field in which the user should enter the number and submit the form. I have put the agent to run from WebQuerySave but i am unsure if he is triggered because I use :

document.forms[0].submit(); on my submit button I get Form proccessed when i submit! I dont get the print stuff from the code.

The user doesnt need to edit anything in the form(s) he enteres the data and he recieves other data it doesnt mather how the data is displayed(messagebox, new page, existing page etc).

Basicaly when he enteres the number in the field I will create an account for the user that the number refers to and send him the account data back so he can access the account (where are an ISP).

Thanks for the help.

Brane

P.S. It would be really nice if we could contact over messenger or skype(dont have a micro) so i could explain my problem better to you guys

Subject: Contact

My MSN and email are navarre_dave@yahoo.com

I’m in GMT -5, so our working hours might not overlap much.

Subject: Just open his user doc

When the user types in the account number, all you need to do is open his user document in the browser window.

So, instead of a Notes agent, just have javascript that computes the URL to open his account document.

Put one field on your document, named AccountNumber. Put a button on there with the following Javascript:

location.href = “WICRnlg/” + document.forms[0].AccountNumber.value + “?OpenDocument”

This MIGHT work properly and simply change the browser window to display the account document. There might be some syntax errors to work through, but it should lead you in the right direction.

I would caution you that the great hazard to this is that someone who wants to guess account numbers can acquire a bunch of usernames and passwords this way.

Dave Navarre

Chub Toad

(I used to have a business called Chub Toad, though perhaps I should be signing as Dave Navarre, Centretek Solutions…)

Subject: Web vs client

Not to be trite, but this looks like it might be an excellent time to learn about Javascript and AJAX/or JSON since they are perfect for what you are trying to do. With a well thought-out framework, you can simplify the process to a very simple procedure:

  1. Trigger javascript function via a button or other form process.

  2. This function sets up a url to your agent and initializes the objects you need to make AJAX calls (if you’re using AJAX, you need the xmlhttprequest object… or you could use JSON).

Here is an ajax call I use often. It passes parameters to the agent via the url for filename, viewunid (both are global variables) and a reference view unid (which is a local variable and is passed to the function in the call).

function populateViewArray(refviewunid){

//populate the view div in the nav bar with links to all of the views, in alphabetical order.

var url = “agtGetViewsProd?openagent&dbname=” + filename + “&viewunid=” + refviewunid;

initRequest(url);

//window.alert("got this far");

req.onreadystatechange = processViews; //this is the callback function where you handle your xml return to update the fields.

req.open("GET", url, true); //this triggers the agent (though it can also be a view formatted as xml)

req.send(null);

}

  1. The call is made to your agent via the url (te req.open in # 2 above). You can simply modify your code so that, instead of writing to the document, you use print statements and build your xml that is returned.

  2. The javascript function then passes control to another function to parse the returned xml (the req.onreadystatechange in # 2 above)

  3. The parser function called by onreadystatechange takes each piece of xml and places the text in the appropriate field

For example… from your example, you would want the xml returned by the agent in a manner something like this:

strReturnMesg contains any status messages you want to display on your form and can be left blank or left out. The carriage returns at the end of each line are used only for formatting (I often use an alert box or print my return to a div on the page for testing and having each xml entity on its own line allows for improved debugging).

d_b = “<doc_broj>” + vwdoc.doc_broj(0) + “</doc_broj>”

un = “” + usrnm + “”

brjUgvr = “” + brjUgvr+ “”

strReturnResults = d_b + un + brjUgvr 'This variable simply makes it easier to use these three elements together.

Dim outputstring As String

outputstring$ = "Content-Type: text/xml" + Chr$(10) 

outputstring$ = outputstring$ + {<?xml version="1.0" ?>} + Chr$(10)

outputstring$ = outputstring$ + {<data>} + Chr$(10)

outputstring$ = outputstring$ +{<message>} + Chr$(10)

outputstring$ = outputstring$ + strReturnMsg + Chr$(10)

outputstring$ = outputstring$ +{</message>} + Chr$(10)

If strReturnResults <> "" Then

	outputstring$ = outputstring$ + strReturnResults + Chr$(10)

End If	

outputstring$ = outputstring$ + {</checkinfo>} + Chr$(10)

'The cache-control statement will prevent the xml from being cached on the page.

Print "Cache-Control: no-cache"



'Return the xml so it can be parsed by the javascript function on the form

Print outputstring$ 'this returns the xml to the javascript callback function

A useful technique in the callback function, is to throw an alert with req.responseText in it to display the xml/html/text that you obtained from the agent. This will show you that you have the data you expect. A search on AJAX requests will give you a list of common HTTP messages that you should trap for in your callback function.

Subject: RE: Web vs client

I am not sure if I can build something this complicated. I am new in lotus and I have collected a good knowlege on the client side but almost nothing on the web side. How long would it take for me to build it? It would be a great thing to learn something new.

Thank you Joel

Brane

Subject: Web vs client

You should note that only Backend classes work for web. The Front end classes which has “UI” like NotesUIWorkspace only works for client.

Better way is to code your agent using backend classes which will work for both Web and Client.

–Phani

Subject: RE: Web vs client

The only problem I have is that I cant insert the retrieved values from the backend doc into the doc I have opened in the browser.

Should i create a backend document identical to the frontend and open it in a new window.

Would this work!

Thanks

Subject: RE: Web vs client

Hi Brane

You can access the lotus script in the web only through the agents.

You cannot use front end classes as suggested in the first response. If you are running the mentioned code in the client as well as web.,

fIrst check the browser type.

If the browsertype is notes.,

set doc=ws.currentdocument.document

otherwise.,

set doc =session.documentcontext

and keep the rest of the code as usual