在Domino中使用Java代理创建文档实例参考

import lotus.domino.Agent;
import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.RichTextItem;
import lotus.domino.RichTextStyle;
import lotus.domino.Session;
import lotus.domino.View;

/*
* 作者:wnight88 功能:在流程结束后在发文表单中创建文档 时间:2008-13-14
*/

public class CreateDocInSwCZJ extends AgentBase
{

  public void NotesMain()
  {

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

      System.out.println("开始代理");
      // 获得当前的代理
      Agent agent = agentContext.getCurrentAgent();
      // 获得代理所在的数据库
      Database currentDB = agentContext.getCurrentDatabase();
      // 获得代理所在数据库中使用本代理的文档
      Document currentDoc = currentDB.getDocumentByID(agent
          .getParameterDocID());
      // 获得当前数据库和数据库中的文档
      Database thisDB = session.getDatabase(currentDB.getServer(),
          "dhfjq/fw.nsf");
      Document thisDoc = thisDB.getDocumentByUNID(currentDoc
          .getItemValueString("goalUNID"));

      // 获得工作流实例库中的正文
      Database workInstanceDB = session.getDatabase(
          currentDB.getServer(), "dhfjq/workinstance.nsf");
      View workInstanceView = workInstanceDB.getView("wordlist");
      Document workInstanceDoc = workInstanceView.getFirstDocument();
      while (workInstanceDoc != null)
      {
        if (workInstanceDoc.getItemValueString("unid").equals(
            thisDoc.getUniversalID()))
        {
          break;
        }
        workInstanceDoc = workInstanceView
            .getNextDocument(workInstanceDoc);
      }
      // 要拷贝数据到的数据库
      Database subDB = session.getDatabase(currentDB.getServer(),
          "dhfjq/sw.nsf");

      // 创建新文档,并赋所有域的值
      Document subDoc = subDB.createDocument();
      thisDoc.copyAllItems(subDoc, true);
      subDoc.replaceItemValue("form", "NewDoc");
      subDoc.replaceItemValue("unid", subDoc.getUniversalID());
      subDoc.save(true, true);

      // 设置签收人
      String qsr = "金静";
      subDoc.replaceItemValue("EndUser", qsr);
      subDoc.replaceItemValue("AddName", qsr);
      subDoc.replaceItemValue("readflag", new Integer("1"));
      subDoc.replaceItemValue("ProcessUNID",
          "488293C619A52C784825757D00343E90");
      subDoc.replaceItemValue("ProcessSubject", "财政局收文流程");
      subDoc.replaceItemValue("Stauts", "ProcessIng");
      subDoc.replaceItemValue("Author", "金静");
      // subDoc.replaceItemValue("IsNewDocFlag", "yes");
      // subDoc.replaceItemValue("readflag", "1");

      // 创建文档,保存
      if (subDoc.save())
      {
        System.out.println("文档已创建!");
      }
      else
      {
        System.out.println("文档无法创建!");
      }

      // 在workInstance数据库的创建新文档,并拷贝正文
      Document subWorkInstanceDoc = workInstanceDB.createDocument();
      if (workInstanceDoc != null)
      {
        workInstanceDoc.copyAllItems(subWorkInstanceDoc, true);
        // 设置正文文档的ID和新建的文档ID一样,相关联
        subWorkInstanceDoc.replaceItemValue("unid", subDoc
            .getUniversalID());
        // 创建文档,保存
        if (subWorkInstanceDoc.save())
        {
          System.out.println("正文已创建!");
        }
        else
        {
          System.out.println("正文无法创建!");
        }
      }

       
      //发送待办事宜
      Database todoDB = session.getDatabase(thisDB.getServer(), "dhfjq/todo.nsf");
      Document todoDoc = todoDB.createDocument();
      todoDoc.appendItemValue("form", "ShowNeedDo");
      RichTextStyle richStyle = session.createRichTextStyle();
      richStyle.setPassThruHTML(1);
      RichTextItem rti = todoDoc.createRichTextItem("resume");
      rti.appendStyle(richStyle);
      rti.appendText("请尽快办理");
      todoDoc.appendItemValue("username","金静");
      todoDoc.appendItemValue("Subject",subDoc.getItemValueString("Subject"));
      todoDoc.appendItemValue("StartDate",subDoc.getCreated());
      todoDoc.appendItemValue("Type","财政局收文流程");
      String url = "/dhfjq/sw.nsf/0/" + subDoc.getUniversalID() + "?editdocument";
      todoDoc.appendItemValue("URL",url);
      todoDoc.appendItemValue("SentUser","金静");
      // 创建文档,保存
      if (todoDoc.save())
      {
        System.out.println("待办事宜已创建!");
      }
      else
      {
        System.out.println("待办事宜无法创建!");
      }
       

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

你可能感兴趣的:(java,工作,Lotus)