views:

704

answers:

2

I have a Lotus Notes application which actually consists of a template with all the required forms, views and agents needed. It also requires some design elements (a custom form and a view for our own type of documents) from this template to be copied over to the mail template, so after the regular refresh all users have it.

The application works like this: the application database (derived from the template I provide) is created on the Domino server. An agent, running in this database, upon http request, creates a "custom" document in user's mail database.

Then, on the client side, the user can use our view to display this document.

Currently, the deployment procedure goes like this:

  1. Create a "master" application database out of our template.
  2. Fill some data, using the forms and views in that database (to configure how the application works)
  3. Copy the custom form and view to the mail template.
  4. Create our button (to launch our view and/or form) on the mail template.
  5. After the nightly database refresh, all users receive the custom form and the view in their mail database, and they can use the button to view our documents (if any).

Now, I want to easy the admin's work, and automate the copying of the custom form and the view, and also the creation of the button to the mail template.

Any idea how I can do this from a NotesScript, JavaScript, Java?

+1  A: 

That sounds doable with DXL, and I think you can use both LotusScript and Java to accomplish it.

Something along the lines of this should do it in Java:

public class RenderDesign extends AgentBase {
public void NotesMain() {

 try { 
  Session session = getSession();
  AgentContext agentContext = session.getAgentContext();

  DxlImporter myimporter = session.createDxlImporter();
  try {
   myimporter.setDesignImportOption(myimporter.DXLIMPORTOPTION_REPLACE_ELSE_CREATE);
   myimporter.importDxl(this.getDxl(), agentContext.getCurrentDatabase());
   } 
  catch (Exception e) {
   System.out.println(this.getDxl());
   System.out.println(myimporter.getLog());   
  }

 } catch(Exception e) {
  e.printStackTrace();
 }
}

Then just construct a string with the DXL. Use Tools -> DXL Utilities -> Exporter (or Viewer) to inspect the design element you want to add or edit:

public String getDxl(String agentname, String replicaid) {
 return "<?xml version='1.0' encoding='utf-8'?>"+
   "<view name='(auto-view)'> "+/* ... */"</view>";
}

Note that the DXL importer is anything but robust and error-tolerant: You can make the Developer client crash on input that is valid XML and conformant with the DTD. For example, trying to set fieldhint="" on a field. Keep this in mind while developing.

Anders Lindahl
Thanks for the info, but I do not see in that code how I set the "target" database, in which I want to put the design elements.
Sunny
Ah, I accidentally removed the reference to the target database when I edited the code. Target database is a parameter to DxlImporter.importDxl.
Anders Lindahl
Thanks for the correction.
Sunny
+1  A: 

Try looking at these for ideas ---> http://www.openntf.org/projects/pmt.nsf/3f2929edba6ef2808625724c00585215/9fe3084cab2f38ad8625754600078af6!OpenDocument

http://www.benpoole.com/80256B44004A7C14/articles/simpledxl

To avoid some of the DXL known issues you can try to export & import in encoded binary format.

**Update

After looking at your situation a bit more closely, I think the easiest route would be to use template inheritance. So you would copy the elements from your custom template into the Mail template and make sure the elements are setup to inherit from your custom template.

Carlos
Yes, thats how it is now. I just want to automate the copying some how.
Sunny
If template inheritance is setup correctly then why do you need to copy the form again? Any changes you make to the form in your custom template should replicate to the mail template which in turn should replicate into users mail db.
Carlos
That's true - I just wanted to prepare a well looking wizard or something so the admin does not need to manually copy forms and buttons out of the application database (which is based on the template). This is just a polish on the whole "install" process - i.e. it would be nice if the setup instructions are: 1. create a db out of that template; 2. open that db, and click "install", as opposed to: 1. create db; 2. copy these, and these, and these elements in the mail template; 3. change this and this, etc.
Sunny
Ok, then definitely DXL is the way to go. Take a look at the links above.
Carlos
Thanks for the links Carlos, I'll accept the other answer because of the example code, but I still upvote yours. Cheers.
Sunny