I created a FWForm class that will provide all the function that is needed to create and submit a form.
I do a getfield, setField, and new FWForm. This function works in LotusScript and all but copyallitems
work in Java. Thanks for your help.
Problem:
How to pass the current document (AgentContext) to the function.
Sample Agent Code:
import lotus.domino.*;
import java.io.*;
import java.util.*;
import com.law.fwform.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
PrintWriter pw = getAgentOutput();
Database db = agentContext.getCurrentDatabase();
Document doc = agentContext.getDocumentContext();
// Start of API Code
String FormServer = db.getServer(); // Name of the server this archive resides on.
String FormDrawer = db.getFilePath(); // Path and filename of this database.
String FormView = "$FWFormID"; // Name of hidden view in this database that the form blank resides in (don't change).
String FormId = doc.getItemValueString("FormTitle"); // Name of the form blank exactly as it appears in the form blank view.
String ctext = doc.getItemValueString("cname");
// Web Submit code start here
// Check for web login user's name if anonymous post message
String user = doc.getItemValueString("Remote_User");
// String user = doc.getItemValueString("CN=Larry Walsh/OU=LNM3");
String cUser = null;
if ( user == null) {
// System.out.println(" Unknown User name.. Login again to the IBM Forms.<p>");
pw.println ( "<h3>ErrorMsg 1: <font color=00008b><strong>Unknown User name.. Login again to the IBM Forms.</strong><font color=0000ff>" );
return ;
}
// Check to see if user name is hierachical
Name na = session.createName(user);
// Then set Remote_User to the correct name format for notes ids use addreviated, http use common name
if (na.isHierarchical())
{
cUser = na.getAbbreviated();
} else {
cUser = na.getCommon();
}
// Create FormWave document
FWForm newForm = new FWForm(FormServer, FormDrawer, FormView, FormId, pw);
// copy all Items from one document to another
// I tried the following
// boolean flag1 = newForm.InitFWForm(doc);
// String flag1 = newForm.InitFWForm(doc);
// pw.println ( "<h3> Copy all items Format - boolean flag1 = newForm.InitFWForm(doc) <font color=00008b><strong>" + flag1 + "</strong><font color=0000ff>" );
} catch(Exception e) {
PrintWriter ptw = getAgentOutput();
ptw.println ( "<h3> FormWave Submit Error:<font color=00008b><strong>" + e + "</strong><font color=0000ff><br>" );
e.printStackTrace();
}
}
}
Sample FWFrom Class:
package com.law.fwform;
import lotus.notes.*;
import java.io.*;
import java.util.*;
public class FWForm {
private Document blankForm;
public FWForm(String formServerName,
String formDBName,
String formViewName,
String formId,
PrintWriter pw) throws NotesException, FWException {
Session s = Session.newInstance();
Database formDrawerDB = s.getDatabase(formServerName, formDBName);
if (!formDrawerDB.isOpen()) {
throw new FWException("FormDrawer database \""+ formDBName +
"\" on Server \"" + formServerName +
"\" did not open.");
}
View blankBox = formDrawerDB.getView(formViewName);
if (blankBox == null) {
throw new FWException("View \"" + formViewName + "\" was not found.");
}
blankForm = blankBox.getDocumentByKey(formId, true);
if (blankForm == null) {
throw new FWException("Form \""+formId+"\" was not retrieved.");
}
} // FWForm constructor
// Problem area...........
/*
public String InitFWForm() throws FWException {
return "";
} // FWForm.InitFWForm()
*/
// public boolean InitFWForm() throws NotesException, FWException {
public String InitFWForm() throws NotesException, FWException {
Document cdoc = blankForm;
if (cdoc.hasItem("_FWAttribute")) {
String GetAttribute = cdoc.getItemValueString("_FWAttribute");
String GetStatus = cdoc.getItemValueString("_FWStatus");
if ((GetAttribute == "FRM") && (GetStatus == "BLANK")) {
return GetAttribute + " - 1 - " + GetStatus;
}}
return "BBB";
} // FWForm.InitFWForm()
}// class FWForm
Sample LotusScript:
Function InitFWForm(copydoc As NotesDocument) As Integer
If copydoc.HasItem("_FWAttribute") Then
GetAttribute = copydoc.GetItemValue("_FWAttribute")
GetStatus = copydoc.GetItemValue("_FWStatus")
If GetAttribute(0) = "FRM" And GetStatus(0) = "BLANK" Then
Forall i In Me.FWDoc.Items
Call Me.FWDoc.RemoveItem(i.Name)
End Forall
Call copydoc.CopyAllItems(Me.FWDoc, False)
InitFWForm = True
Else
InitFWForm = False
APIErrMsg = "API1N500E"
Exit Function
End If
Else
InitFWForm = False
APIErrMsg = "API1N400E"
Exit Function
End If
End Function

