Home > Domino Tips > Developer > A single form to view and edit any Lotus Notes document
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

A single form to view and edit any Lotus Notes document


Leonard Volovets
01.30.2007
Rating: -3.23- (out of 5)


Lotus Notes and Domino tips, tutorials and how-to articles
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


VIEW MEMBER FEEDACK TO THIS TIP

Conventional wisdom holds that a rich client like Lotus Notes is superior to a thin client like a Web browser. This is true in most cases. However, there is one Lotus Notes-related situation in which only a Web browser will do.

As an example scenario, let's say you have one or more documents with dynamic content -- i.e., the field names are different. Even worse, perhaps you don't even know what the field names/values are ahead of time. The challenge is to create a form that allows for the viewing and editing of such documents.

Lotus Notes is a powerful application, but it doesn't offer any way (that I'm aware of) to create a design element on the fly. Even if there was, it would be much too complicated for an ordinary Notes/Domino developer to make it worthwhile. This leaves us with the Web browser.

The solution to the problem is surprisingly simple. Build a Lotus Notes form that generates a dynamic HTML form based on the content of the document being viewed/edited.

In fact, the solution I'm proposing contains just one Lotus Notes field and one Computed Text value. There are also two agents: a WebQueryOpen agent called "LoadDocData" and a WebQuerySave agent called "SaveDocData".

We'll call the form "Data" so we can refer to it in the code that follows. In addition, let's assume that the Form field in these documents is set to "Data" to make it all work.

(WebQueryOpen) Agent LoadDocData 
(variable declarations omitted for brevity):

NOTE: In the code below, the agent uses the doc.items property to cycle through all the fields in the document and creates an HTML form with editable fields. I advise alphabetically sorting the fields, which was not done here, to make finding document fields on the screen easier.

All the field names and their values point back to a field called $$Record, a name that was arbitrarily chosen by me. When the Lotus Domino server sees this field, it "stuffs" all the data into a single field, making it a multi-value text list. This field plays a central role in the WebQuerySave agent, as you shall see shortly.

Sub Initialize
Set s = New NotesSession
Set sdoc = s.DocumentContext
Set db = s.CurrentDatabase
  
ts =  |<table border=1 
cellspacing=0 width=80% 
align="center">
<tr valign=top><td colspan=2 
bgcolor="808080" align="center">
<b><font size="4" 
color="FFFFF">Document Data<
/font></b></td></tr>
<tr valign=top><td 
width=20%><b>Field Name<
/b></td><td width=60%><
b>Field Value</b></td></tr>|
 te = |</table>|
 rs = |<tr valign=top>|
 re = |</tr>|
 cs = |<td><font size=2>|
 ce = |</font></td>|
 
 Forall f In sdoc.items
nam = f.name
If (Instr ( nam, "$" ) Or Instr (Lcase ( nam ) , "form" ) ) Then
'do nothing, do not expose internal fields
Else   
values = f.values    
fieldHTML = |<input name="$$Record" 
type="hidden" value="| & nam & |"
><input name="$$Record" 
value="| & values(0) & |" size="25" 
maxlength="100">|   
editrow =  rs & cs & nam & ce 
& cs & fieldHTML & ce & re
editbody = editbody & editrow
End If   
End Forall
 
edittable = ts & editbody & te
Call sdoc.ReplaceItemValue ( "EditTable" , edittable )
 
End Sub


(WebQuerySave) Agent SaveDocData 
(again, declarations dropped for sake of brevity)

(In this agent, the field $$Record is 
inspected to identify changes to fields. 
Since the structure of the $$Record is 
"name," "value," "name," "value," etc., 
we can easily identify and set appropriate
 fields with new values.)

Sub Initialize
Set s = New NotesSession
Set sdoc = s.DocumentContext
Set db = s.CurrentDatabase
 
record = sdoc.GetItemValue ("$$Record" )
For n% = Lbound ( record ) To Ubound ( record )
remainder = n% Mod 2
If remainder = 0 Then
fn = record (n%)
Else
tmpvalue = Trim$ ( record (n%) )
Call sdoc.ReplaceItemValue ( fn, value )
End If
Next
End Sub

To put it all together, create a form called "Data" with a field called $$Record (type text, computed, allow multiple values, hidden) and a computed (pass-thru HTML) text value that has the following formula: @If (@IsDocBeingEdited ; EditTable ; ReadTable ), where ReadTable could be the read-only equivalent of the EditTable field calculated in the "LoadDocData" agent above.

Make the "LoadDocData" run on the WebQueryOpen event and "SaveDocData" on the WebQuerySave event and you're done.

Of course, the "Save" link should be provided with the code @Command ( [FileSave] ); @Command ( [FileCloseWindow] ) running behind it.

To make the form a bit more useful, you can check for input/edit errors and dump them into a field called $Errors, which will display if there is something in it.

As a final window-dressing, you could have a $$Return field with the formula: @If (@IsAvailable($Errors) ; "… come back to the edit URL…" ; "… go to some other URL… "). Notice that the agent code assumes single-value fields by working with value(0) part of the field -- but it could certainly be modified to work with more complex data types.

MEMBER FEEDBACK TO THIS TIP

If you need to create actual fields, views, forms, etc., you could also use NotesDXLImporter. It can be somewhat tricky at times though.
—Anders G.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • Tip: How to create a comments field for Lotus Notes documents
  • Tip: Update a field in all Lotus Notes documents using an agent
  • Expert Advice: Dynamically create fields in Lotus Notes
  • Reference Center: Agents tips and resources
  • Reference Center: LotusScript tips and resources

    This tip was submitted to the SearchDomino.com tip library by member Leonard Volovets. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

    Rate this Tip
    To rate tips, you must be a member of SearchDomino.com.
    Register now to start rating these tips. Log in if you are already a member.




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



    RELATED CONTENT
    Lotus Notes Domino Agents
    How the Agent Profiler tool improves Notes/Domino performance
    Run or restart Notes/Domino agents via text messages
    Calculating results for a column in a Lotus Notes view
    Approve Lotus Notes documents using a BlackBerry mobile device
    LotusScript agent indexes Lotus Notes/Domino databases
    Top 10 Lotus Notes/Domino coding and development tips of 2008
    Open documents in Lotus Notes from the Web without a UNID
    Fix and update Lotus Notes documents with limited access
    Verify scheduled agent status with Domino Extensible Language (DXL)
    Top 10 Lotus Notes Domino programming and development tips of 2007

    LotusScript
    LotusScript finds the first occurrence of a string from the right
    Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
    Search Microsoft Active Directory with LotusScript
    Three steps to trap and handle save conflicts with LotusScript
    Troubleshoot agents by displaying LotusScript variables online
    LotusScript sorts lists alphabetically
    Run or restart Notes/Domino agents via text messages
    LotusScript code rebuilds corrupted busytime.nsf file
    Soft-code item names to facilitate LotusScript management
    LotusScript agent automates selective mail file replication

    Agent
    Run or restart Notes/Domino agents via text messages
    Approve Lotus Notes documents using a BlackBerry mobile device
    LotusScript agent indexes Lotus Notes/Domino databases
    Open documents in Lotus Notes from the Web without a UNID
    Fix and update Lotus Notes documents with limited access
    Verify scheduled agent status with Domino Extensible Language (DXL)
    How to export data from a Lotus Notes database to a CSV file
    Enable or disable scheduled agents without opening the Lotus Notes database design
    Creating custom views in Lotus Notes databases
    Editing fields in a Lotus Notes view with Ajax

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts