我有一个保存文档的按钮,并为添加到其中的用户创建响应文档。我有一个@Unique函数来为我的表格编号生成一个随机数。
我遇到的问题是,当我进入并编辑文档并保存&发送响应文档,它将其视为不同的文档,因此表单编号也在变化。父文档的表单编号需要保持不变。
是否有一种简单的方法可以检查是否已有表格编号,如果有,是否保持相同?如果没有,请继续给它一个随机数。
以下是我的Save&中的代码。发送按钮:
// get handle to names list
var item = new Array(document1.getItemValue("assignedassociates"));
var attach:String;
// loop through the list to create a review doc for each person listed
for(var i = 0; i <= (@Elements(item)-1); i++){
var newdoc:NotesDocument = database.createDocument()
newdoc.replaceItemValue("Form", "Review");
newdoc.replaceItemValue("datecreated", document1.getItemValueString("datecreated"));
newdoc.replaceItemValue("formnumber", document1.getItemValueString("formnumber"));
newdoc.replaceItemValue("title", document1.getItemValueString("title"));
newdoc.replaceItemValue("department", document1.getItemValueString("department"));
newdoc.replaceItemValue("description", document1.getItemValueString("description"));
newdoc.replaceItemValue("assignedassociates", item[i]);
newdoc.replaceItemValue("Status", "Sent");
// attachment URL
// calculate file path
// check for multiple attachments, create multiple URLs
attach = "http://domtest01.hendricks.org/chad/bloodhound.nsf/0/" + document1.getDocument().getUniversalID() +
"/$file/" + @AttachmentNames() + "?openElement";
newdoc.replaceItemValue("AttachmentURL", attach);
// set the security fields on the new doc we created
setSecurityFields(newdoc, item[i]);
newdoc.save();
}
// update document history
var cuser:NotesName=session.createName(@UserName()); // gets user name in name field
updateHistoryField(document1.getDocument(),cuser.getCommon(),"EditHistory","form_create"); // call function
// show assigned docs
requestScope.put("showContainer", true);
以下是我在页面中的代码:
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex"
styleClass="forms"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.data>
<xp:dominoDocument
var="document1"
formName="Create">
</xp:dominoDocument>
</xp:this.data>
<xp:table>
<xp:tr>
<xp:td style="font-weight:bold">Created By:</xp:td>
<xp:td>
<xp:text
escape="true"
id="computedField1">
<xp:this.value><![CDATA[#{javascript:var userName:NotesName = session.createName(@UserName());
return(userName.getCommon());}]]></xp:this.value>
</xp:text>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Date: </xp:td>
<xp:td>
<xp:inputText
id="inputText2"
value="#{document1.datecreated}" defaultValue="#{javascript:{javascript:@Today()}}">
<xp:this.validators>
<xp:validateRequired message="You must select a Date."></xp:validateRequired>
</xp:this.validators>
<xp:dateTimeHelper id="dateTimeHelper1"></xp:dateTimeHelper>
<xp:this.converter>
<xp:convertDateTime
type="date"
dateStyle="short">
</xp:convertDateTime>
</xp:this.converter>
</xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Form Number:</xp:td>
<xp:td>
<xp:inputText
id="inputText3"
value="#{document1.formnumber}"
required="true" disabled="true">
<xp:this.validators>
<xp:validateRequired message="You must enter a Form Number."></xp:validateRequired>
<xp:validateLength message="Form Number must be 8 characters in length."></xp:validateLength>
</xp:this.validators>
<xp:this.defaultValue><![CDATA[#{javascript:session.evaluate("@Unique")}]]></xp:this.defaultValue></xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Title: </xp:td><xp:td>
<xp:inputText
id="inputText1"
value="#{document1.title}"
maxlength="60"
required="true">
<xp:this.validators>
<xp:validateLength maximum="60"></xp:validateLength>
<xp:validateRequired message="You must enter a Title."></xp:validateRequired>
</xp:this.validators>
</xp:inputText> </xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Department:</xp:td>
<xp:td>
<xp:comboBox
id="department"
value="#{document1.department}"
rendered="#{javascript:document1.isEditable()}">
<xp:this.validators>
<xp:validateExpression message="You must select a Department">
<xp:this.expression><![CDATA[#{javascript:value != "Select One"}]]></xp:this.expression>
</xp:validateExpression>
</xp:this.validators>
<xp:selectItem
itemLabel="Select One"
itemValue="Select One"
id="selectItem1">
</xp:selectItem>
<xp:selectItems id="selectItems1">
<xp:this.value><![CDATA[#{javascript:var dbName = ["", "aApplications\\HCHPhoneBk.nsf"];
@DbColumn( dbName , "DeptNameLookUp", 1);}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
<xp:text
escape="true"
id="computedField2"
value="#{document1.department}"
rendered="#{javascript:!document1.isEditable()}">
</xp:text>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Description:</xp:td>
<xp:td>
<xp:inputTextarea
id="inputTextarea1"
value="#{document1.description}"
style="width:300.0px;height:96px"
required="true">
<xp:this.validators>
<xp:validateRequired message="You must enter a Description."></xp:validateRequired>
</xp:this.validators>
</xp:inputTextarea>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Attachments:</xp:td>
<xp:td>
<xp:fileUpload
id="attachments"
value="#{document1.attachments}">
</xp:fileUpload>
 </xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold"></xp:td>
<xp:td>
<xp:fileDownload
rows="30"
id="fileDownload1"
displayLastModified="false"
hideWhen="true"
displaySize="true"
displayCreated="false"
value="#{document1.attachments}"
displayType="false" allowDelete="true">
</xp:fileDownload>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td
rowspan="2"
style="font-weight:bold">
Associates to
<xp:br id="br1"></xp:br>
review document:
</xp:td>
<xp:td rowspan="2">
<xe:djextNameTextBox
id="djextNameTextBox1"
multipleSeparator=","
multipleTrim="true"
value="#{document1.assignedassociates}"
rendered="#{javascript:document1.isEditable()}">
</xe:djextNameTextBox>
  
<xe:namePicker
id="namePicker1"
for="djextNameTextBox1"
pickerIcon="/Symbol+Add.gif">
<xe:this.dataProvider>
<xe:namePickerAggregator>
<xe:this.dataProviders>
<xe:dominoNABNamePicker
addressBookDb="HCHPhoneBk"
nameList="people">
</xe:dominoNABNamePicker>
</xe:this.dataProviders>
</xe:namePickerAggregator>
</xe:this.dataProvider>
</xe:namePicker>
</xp:td>
</xp:tr>
<xp:tr></xp:tr>
</xp:table>
<xp:messages id="messages1"></xp:messages>
<xp:br></xp:br>
<xp:button
id="button4"
rendered="#{javascript:document1.isEditable()}">
<xp:this.value><![CDATA[Save & Assign Response Documents]]></xp:this.value>
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="document1"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:// get handle to names list
var item = new Array(document1.getItemValue("assignedassociates"));
var attach:String;
// loop through the list to create a review doc for each person listed
for(var i = 0; i <= (@Elements(item)-1); i++){
var newdoc:NotesDocument = database.createDocument()
newdoc.replaceItemValue("Form", "Review");
newdoc.replaceItemValue("datecreated", document1.getItemValueString("datecreated"));
newdoc.replaceItemValue("formnumber", document1.getItemValueString("formnumber"));
newdoc.replaceItemValue("title", document1.getItemValueString("title"));
newdoc.replaceItemValue("department", document1.getItemValueString("department"));
newdoc.replaceItemValue("description", document1.getItemValueString("description"));
newdoc.replaceItemValue("assignedassociates", item[i]);
newdoc.replaceItemValue("Status", "Sent");
// attachment URL
// TO DO - check for server name and put in appropriate server name and format
// calculate file path
// check for multiple attachments, create multiple URLs
attach = "http://domtest01.hendricks.org/chad/bloodhound.nsf/0/" + document1.getDocument().getUniversalID() +
"/$file/" + @AttachmentNames() + "?openElement";
newdoc.replaceItemValue("AttachmentURL", attach);
// set the security fields on the new doc we created
setSecurityFields(newdoc, item[i]);
newdoc.save();
}
// update document history
var cuser:NotesName=session.createName(@UserName()); // gets user name in name field
updateHistoryField(document1.getDocument(),cuser.getCommon(),"EditHistory","form_create"); // call function
// show assigned docs
requestScope.put("showContainer", true);}]]></xp:this.script>
</xp:executeScript>
<xp:changeDocumentMode
mode="readOnly"
var="document1">
</xp:changeDocumentMode>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button> <xp:button id="button1" value="Edit" rendered="#{javascript:!document1.isEditable()}">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:changeDocumentMode mode="edit" var="document1">
</xp:changeDocumentMode>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:// update document history
var cuser:NotesName=session.createName(@UserName()); // gets user name in name field
updateHistoryField(document1.getDocument(),cuser.getCommon(),"EditHistory","form_create"); // call function}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:button id="button5">
<xp:this.value><![CDATA[#{javascript:if (document1.isEditable()){
return "Cancel";
}else{
return "Close";
}}]]></xp:this.value>
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete" immediate="true">
<xp:this.action>
<xp:openPage name="$$PreviousPage"></xp:openPage>
</xp:this.action></xp:eventHandler></xp:button>
<xp:this.beforePageLoad><![CDATA[#{javascript:requestScope.put("showContainer", false)}]]></xp:this.beforePageLoad><xp:br></xp:br>
<xp:br></xp:br>
<xp:panel id="outerContainer">
<xp:panel id="innerContainer">
<xp:viewPanel
rows="30"
id="viewPanel1"
var="rowData">
<xp:this.facets>
<xp:pager
partialRefresh="true"
layout="Previous Group Next"
xp:key="headerPager"
id="pager1">
</xp:pager>
<xp:viewTitle
xp:key="viewTitle"
id="viewTitle1" value="Sent To">
</xp:viewTitle>
</xp:this.facets>
<xp:this.data>
<xp:dominoView
var="view1"
viewName="Children">
<xp:this.categoryFilter><![CDATA[#{javascript:document1.getItemValueString("Title");}]]></xp:this.categoryFilter>
</xp:dominoView>
</xp:this.data>
<xp:viewColumn
columnName="$6"
id="viewColumn1">
<xp:this.converter>
<xp:convertDateTime
type="date"
dateStyle="short">
</xp:convertDateTime>
</xp:this.converter>
<xp:viewColumnHeader
value="Date"
id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="department"
id="viewColumn2">
<xp:viewColumnHeader
value="Department"
id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="formnumber"
id="viewColumn3">
<xp:viewColumnHeader
value="Form #"
id="viewColumnHeader3">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="assignedassociates"
id="viewColumn4"
displayAs="link"
openDocAsReadonly="#{javascript:rowData.getColumnValue('Status') === 'Responded'}">
<xp:viewColumnHeader
value="Reviewer"
id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="Status"
id="viewColumn5">
<xp:viewColumnHeader
value="Status"
id="viewColumnHeader5">
</xp:viewColumnHeader>
</xp:viewColumn>
</xp:viewPanel>
</xp:panel>
</xp:panel>
<xp:text escape="true" id="computedField3"><xp:this.value><![CDATA[#{javascript:"requestScope.showContainer=" + requestScope.get("showContainer")}]]></xp:this.value></xp:text>
<xp:br></xp:br>
<xc:layout_EditHistory></xc:layout_EditHistory></xp:view>
答案 0 :(得分:1)
试试这个(包括回收):
var item:java.util.Vector = document1.getItemValue("assignedassociates");
if (!document1.hasItem("formnumber")) {
document1.replaceItemValue("formnumber",session.evaluate("@Unique"));
}
for(var curItem in item) {
try {
var newdoc:NotesDocument = database.createDocument();
newdoc.replaceItemValue("Form", "Review");
newdoc.replaceItemValue("datecreated", document1.getItemValueString("datecreated"));
newdoc.replaceItemValue("formnumber", document1.getItemValueString("formnumber"));
newdoc.replaceItemValue("title", document1.getItemValueString("title"));
newdoc.replaceItemValue("department", document1.getItemValueString("department"));
newdoc.replaceItemValue("description", document1.getItemValueString("description"));
newdoc.replaceItemValue("assignedassociates", curItem);
newdoc.replaceItemValue("Status", "Sent");
// attachment URL
var attach = "http://domtest01.hendricks.org/chad/bloodhound.nsf/0/" + document1.getDocument().getUniversalID() +
"/$file/" + @AttachmentNames() + "?openElement";
newdoc.replaceItemValue("AttachmentURL", attach);
// set the security fields on the new doc we created
setSecurityFields(newdoc, curItem);
newdoc.save();
// Cleanup!
newdow.recycle();
} catch (e) {
// Some clever error handling here
}
}
// update document history
var cuser:NotesName=session.createName(@UserName()); // gets user name in name field
updateHistoryField(document1.getDocument(),cuser.getCommon(),"EditHistory","form_create");
// show assigned docs
requestScope.put("showContainer", true);
告诉我们它是怎么回事!
的更新强> 的
如果在创建后不应更改表单编号
,请将其用于行 <xp:tr>
<xp:td style="font-weight:bold">Form Number:</xp:td>
<xp:td>
<xp:inputText
id="inputText3"
value="#{document1.formnumber}" disabled="true"
required="true" rendered="#{javascript:document1.isNewNote()}">
<xp:this.validators>
<xp:validateRequired message="You must enter a Form Number."></xp:validateRequired>
<xp:validateLength message="Form Number must be 8 characters in length."></xp:validateLength>
</xp:this.validators>
<xp:this.defaultValue><![CDATA[#{javascript:session.evaluate("@Unique")}]]></xp:this.defaultValue>
</xp:inputText>
<xp:text escape="true" id="displayText3"
value="#{document1.formnumber}"
rendered=""#{javascript:!document1.isNewNote()}"></xp:text>
</xp:td>
</xp:tr>
这接近你目前的做法。但实际上我仅使用显示字段并在document1数据源的NewDocument事件中添加值。所以你的行看起来像这样:
<xp:tr>
<xp:td style="font-weight:bold">Form Number:</xp:td>
<xp:td>
<xp:text escape="true" id="displayText3"
value="#{document1.formnumber}"></xp:text>
</xp:td>
</xp:tr>
在Data - document1 - queryNewDocument下的events选项卡中,您添加为JavaScript:
document1.replaceItemValue("formnumber",session.evaluate("@Unique"));
这应该可以解决问题。另一个注释:使用LABELS作为标签并使用CSS进行格式化。大胆的标签很不合时宜,因此在CSS中使用单一定义会使采用变得更容易。如果你打算用多种语言(即使在美国也有中文和西班牙语,或者如果你的工作为7/11,那么你需要标签)