我试图使用旧的LotusScript代理预先填充XPage上的一些字段(创建一个新的doc).我在XPage上的代码是:
<xp:dominoDocument var="document1"
formName="myForm">
<xp:this.postNewDocument><![CDATA[#{javascript:
var agent = database.getAgent("MyAgent");
document1.save();
agent.runOnServer(document1.getNoteID());
}]]></xp:this.postNewDocument>
</xp:dominoDocument>
<xp:inputText value="#{document1.fname}" id="fname"
styleClass="formInputText">
<xp:this.defaultValue><![CDATA[#{javascript:
document1.getItemValueString("fname");}]]></xp:this.defaultValue>
</xp:inputText>
Run Code Online (Sandbox Code Playgroud)
代理(对于此示例)是:
Dim agent As NotesAgent
Dim db As NotesDatabase
Sub Initialize
Dim rDoc As NotesDocument
Dim s As New NotesSession
Set db = s.CurrentDatabase
Set agent = s.CurrentAgent
Set rDoc = db.GetDocumentByID(agent.Parameterdocid)
rDoc.fname = "Barney"
rDoc.lname = "Rubble"
Call rDoc.Save(True, True)
End Sub
Run Code Online (Sandbox Code Playgroud)
我知道代理正在运行(如果我检查Notes客户端中的doc属性,代理日志会显示此文件并且文档上的字段已完成)但是XPage上的字段始终为空白?是否可以从LS代理预填充?我添加了document1.save()所以我知道我得到了一个有效的NoteID传递(再次是相同的 - 通过记录检查) - 任何洞察感激地收到...
您可以将文档传递到代理程序运行中.将unid传递给代理上下文的方法不会让你到达那里.你需要
agent.runwithDocumentContext(doc)
Run Code Online (Sandbox Code Playgroud)
请看这里的一些例子:http://www.wissel.net/blog/d6plinks/SHWL-8SF7AH
不要保存文档.您需要将代理重新编写为JavaBean.缩短处理时间.
我实际上会做什么:使用bean作为数据源,使处理验证,默认值等更容易.
它的工作量比它看起来要少,它可以减少一些技术债务(总是存在技术债务).
更新
我在示例应用程序中尝试过它.这是我的经纪人:
Sub Initialize
Dim db As NotesDatabase
Dim rDoc As NotesDocument
Dim s As New NotesSession
Set db = s.CurrentDatabase
Set rDoc = s.Documentcontext
rDoc.fname = "Barney"
rDoc.lname = "Rubble"
End Sub
Run Code Online (Sandbox Code Playgroud)
与您的代码有两个主要区别:a)DocumentContext而不是parameterdocid并且不保存文档.
然后页面看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument var="document1" formName="person">
<xp:this.postNewDocument><![CDATA[#{javascript:var agent = database.getAgent("Background");
var doc = document1.getDocument();
agent.runWithDocumentContext(doc);}]]></xp:this.postNewDocument>
</xp:dominoDocument>
</xp:this.data>
<xp:label value="First name:" id="fName_Label1" for="fName1">
</xp:label>
<xp:inputText value="#{document1.fName}" id="fName1"></xp:inputText>
<br />
<xp:label value="Last name:" id="lName_Label1" for="lName1"></xp:label>
<xp:inputText value="#{document1.lName}" id="lName1"></xp:inputText>
<xp:button value="Save" id="button1"><xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true"></xp:eventHandler></xp:button>
</xp:view>
Run Code Online (Sandbox Code Playgroud)
主要区别在于:
最后:代理必须设置为"以Web用户身份运行"(可能已经存在).像魅力一样工作(我仍然会选择一个豆).