I have a button which should change the value of a field on the selected documents from a viewpanel. But whatever I do, I also switched the columns where the checkbox was, I always get 0 ids.
Here is my viewPanel:
<xp:viewPanel rows="30" id="viewPanel1" pageName="/Account.xsp" var="rowData">
<xp:this.facets>
<xp:pager partialRefresh="true"
layout="FirstImage PreviousImage SeparatorPage Group NextImage LastImage"
xp:key="headerPager" id="pager1" alwaysCalculateLast="true">
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view1" viewName="Konten\Fehler">
<xp:this.search><![CDATA[#{javascript:return viewScope.get( "searchString" );}]]></xp:this.search>
</xp:dominoView>
</xp:this.data>
<xp:viewColumn id="viewColumn10" columnName="$errCodes">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header" id="viewColumnHeader10" value="Fehler">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
<xp:viewColumn id="viewColumn9" styleClass="total">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header" id="viewColumnHeader9">
</xp:viewColumnHeader>
</xp:this.facets>
<xp:this.value><![CDATA[#{javascript:if( rowData.isCategory() )
{
return rowData.getColumnValue( "$11" )
}}]]></xp:this.value>
<xp:this.converter>
<xp:convertNumber type="number" integerOnly="true">
</xp:convertNumber>
</xp:this.converter>
</xp:viewColumn>
<xp:viewColumn id="viewColumn8" columnName="accountnumber" displayAs="link">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header" id="viewColumnHeader8" value="Konto" sortable="true">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
<xp:viewColumn columnName="iban" id="viewColumn1" showCheckbox="true">
<xp:viewColumnHeader value="IBAN" id="viewColumnHeader1" sortable="true">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="accounttype" id="viewColumn2">
<xp:viewColumnHeader value="Typ" id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn id="viewColumn7" columnName="$info">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header" id="viewColumnHeader7" value="Fehlermeldung" sortable="true">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
</xp:viewPanel>
and the button
<xp:button value="Ausblenden" id="button1" styleClass="btn-info">
<xp:eventHandler event="onclick" submit="true" refreshMode="norefresh">
<xp:this.action>
<![CDATA[#{javascript:
var viewPanel = getComponent( "viewPanel1" );
var docIDArray = viewPanel.getSelectedIds();
for( i=0; i < docIDArray.length; i++ )
{
var docId = docIDArray[i];
var doc:NotesDocument = database.getDocumentByID( docId );
doc.replaceItemValue( "$shErr", 0 );
doc.save();
}
}]]>
</xp:this.action>
</xp:eventHandler>
</xp:button>
but somehow getSelectedIds returns no id at all.
Any ideas? Thanks for your time!
If you try the below, do you get anything from unidArray?
var unidArray = new Array();
for(i=0; i < docIDArray.length; i++) {
var unid=database.getDocumentByID(docIDArray[i]).getUniversalID();
unidArray.push(unid);
}
Related
I am trying to get selected documents from a view and save as separate documents
Here is the design of the xpage
A combo box on the top, a view with check box (this view is used for selection), a button for save the selection values from the view and the combo box. Also there will another view which will display the saved values.
From this post, I can get the unid of selected documents and save to view scope variable. The add button can save the selected value from the combo box and the view and show the result in another view.
However, if I choose more than one value in the view and click save, it saves all values in one document. So I try to use for loop to loop through the selected values in view and save, it still saves one value only in one document.
<xp:table id="table1a">
<xp:tr>
<xp:td id="table1">
<xp:comboBox id="comboBox1"
dojoType="dijit.form.ComboBox" style="width:250.0px"
value="#{document1.Category}">
<xp:selectItems id="selectItems3">
<xp:this.value><![CDATA[#{javascript:var SetFirstValueBlank = #Text("");
return SetFirstValueBlank;
}]]></xp:this.value>
</xp:selectItems>
<xp:selectItems id="selectItems4">
<xp:this.value><![CDATA[#{javascript:#Unique(#DbColumn(#DbName(), "CategoryListView", 1));}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="table1a">
</xp:eventHandler>
</xp:comboBox>
<xp:text escape="true" id="computedField1">
</xp:text>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:viewPanel rows="10" id="viewPanel1" var="rowData">
<xp:this.data>
<xp:dominoView var="view1"
viewName="hListView">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="ItemName"
id="viewColumn1" style="background-color:rgb(255,255,255)"
showCheckbox="true">
<xp:viewColumnHeader value="Item Name"
id="viewColumnHeader1" rendered="false">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:this.facets>
<xp:pager partialRefresh="true"
layout="Previous Group Next" xp:key="footerPager" id="pager2">
</xp:pager>
</xp:this.facets>
</xp:viewPanel>
<xp:br></xp:br>
<xp:button value="Add" id="button1"
style="height:35.0px">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var Category = getComponent("comboBox1").getValue();
var viewPanel=getComponent("viewPanel1");
var docIDArray=viewPanel.getSelectedIds();
var unidArray = new Array();
for(i=0; i < docIDArray.length; i++) {
var unid=database.getDocumentByID(docIDArray[i]).getUniversalID();
unidArray.push(unid);
}
viewScope.put("unidArray", #Implode(unidArray, ","));
for(var i=0; i< unidArray.length;i++ )
{
document1.replaceItemValue("ItemName", unidArray[i]);
document1.save();
}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:viewPanel rows="6" id="viewPanel2">
<xp:this.data>
<xp:dominoView var="view2" viewName="CategoryItemView">
<xp:this.categoryFilter><![CDATA[#{javascript:getComponent("comboBox1").getValue();}]]></xp:this.categoryFilter>
</xp:dominoView>
</xp:this.data>
<xp:this.rendered><![CDATA[#{javascript:var value = getComponent("comboBox1").getValue();
if(value =="" || value == null)
{
return false;
}
else
{
return true;
}}]]></xp:this.rendered><xp:viewColumn id="viewColumn4" columnName="Category" rendered="false">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header" id="viewColumnHeader4" value="Category">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
<xp:viewColumn id="viewColumn3" columnName="$10">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header" id="viewColumnHeader3" value="Category">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
<xp:viewColumn columnName="ItemName" id="viewColumn2">
<xp:viewColumnHeader value="Item" id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next" xp:key="footerPager" id="pager3">
</xp:pager>
</xp:this.facets></xp:viewPanel><xp:br></xp:br></xp:td>
</xp:tr>
</xp:table>
Would someone let me know how to save multiple values in separate documents please? Thank you.
(edit: some of previous content are removed)
I think I will focus on how to save multiple value as separate documents first because this part is quite important in the program, once I can save as separate documents, there will another function that needs the result to process.
I review the code, I think I will still use for loop but unfortunately, it still saves one document only.
I'm guessing the document1 object is bound to a on the XPage, which is only created when the XPage is opened. To cause your button to create multiple documents, the for loop needs to modified :
var oneOfMany : NotesXspDocument;
for(var i=0; i< unidArray.length;i++ )
{
oneOfMany = database.createDocument();
oneOfMany.replaceItemValue( "Category", document1.getItemValue("Category" ) );
oneOfMany.replaceItemValue("ItemName", unidArray[i]);
oneOfMany.replaceItemValue("form", "MyFormName" );
oneOfMany.save();
}
Because it no longer uses document1, this loop will need to populate the other items you need such as the form, for example MyFormName as in the example.
I have a viewpanel that I am using the "Search in view results" feature. The view has a pager. The scoped variable that I use for the search is null initially and the user has an option to choose from a list to create a search. The initial null search brings back about 1000 records and the user can use a page selector to scroll through the entries if they wish. If the user chooses say page 5 and then creates a search, the pager headers show up but no search results. In order to see the search results the user has to manually click on "first", then the pager resets and the results of the search appear.
I saw a solution in ViewPanel filter by StartKeys...but pager don't Update. However, I cannot use getAllEntriesByKey because I am returning the results of a search not a filter.
Here is the code, stripped down to the basics. In my application the user can create a search with up to 4 terms.
Thanks,
---Lisa&
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:table>
<xp:tr>
<xp:td><xp:comboBox id="TeacherComboBox" value="#{viewScope.TeacherComboBox}">
<xp:selectItems id="selectItems9">
<xp:this.value><![CDATA[#{javascript:return ""}]]></xp:this.value>
</xp:selectItems>
<xp:selectItems id="selectItems10">
<xp:this.value><![CDATA[#{javascript:var dbName = session.getCurrentDatabase();
var view = ("CampusCodes");
var CampusList = #Unique(#DbColumn(dbName,view,1));
return CampusList}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox></xp:td>
</xp:tr>
<xp:tr>
<xp:td><xp:button id="button14" styleClass="BlueButtonSmall" value="Apply Search">
<xp:eventHandler event="onclick"
submit="true" refreshMode="complete" id="eventHandler17">
<xp:this.action><![CDATA[#{javascript:viewScope.TeacherSearchFormula = null;
var TeacherSearchFormula = null;
var Campus = null;
if (!!viewScope.TeacherComboBox) {
Campus = '[CampusNum]' + ' CONTAINS ' + viewScope.TeacherComboBox;
};
if (!!Campus) {
TeacherSearchFormula = Campus;
};
if (!!TeacherSearchFormula) {
viewScope.TeacherSearchFormula = TeacherSearchFormula;
print("viewScope.TeacherSearchFormula = ",viewScope.TeacherSearchFormula);
viewScope.ErrorLabel4T = "Search did not return any teachers.";
} else {
var varAlert = "Please choose some filters."
var al = "alert('"+ varAlert +"')";
view.postScript(al);
}}]]></xp:this.action>
</xp:eventHandler>
</xp:button><xp:button id="button15" styleClass="BlueButtonSmall" value="Clear Search">
<xp:eventHandler event="onclick"
submit="true" refreshMode="complete" id="eventHandler19">
<xp:this.action><![CDATA[#{javascript:getComponent("TeacherComboBox").setValue("");
viewScope.TeacherSearchFormula = null;
viewScope.TeacherComboBox = null;
}]]></xp:this.action>
</xp:eventHandler>
</xp:button></xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:viewPanel rows="30" id="viewPanel1">
<xp:this.facets>
<xp:pager xp:key="headerPager" id="pager1"
for="viewPanel1" partialRefresh="true">
<xp:pagerControl type="First"
id="pagerControl1">
</xp:pagerControl>
<xp:pagerControl type="Next"
id="pagerControl2">
</xp:pagerControl>
<xp:pagerControl type="Group"
id="pagerControl3">
</xp:pagerControl>
<xp:pagerControl type="Previous"
id="pagerControl4">
</xp:pagerControl>
<xp:pagerControl type="Last"
id="pagerControl5">
</xp:pagerControl>
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view1"
viewName="NISDTeacher" sortColumn="$1"
search="#{javascript:viewScope.TeacherSearchFormula}">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="CampusNum"
id="viewColumn1">
<xp:viewColumnHeader value="CampusNum"
id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="$1" id="viewColumn2">
<xp:viewColumnHeader value="TeacherFull"
id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="CampusName"
id="viewColumn3">
<xp:viewColumnHeader value="CampusName"
id="viewColumnHeader3">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="TeacherEnumber"
id="viewColumn4">
<xp:viewColumnHeader value="TeacherEnumber"
id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="TeacherPTitle"
id="viewColumn5">
<xp:viewColumnHeader value="TeacherPTitle"
id="viewColumnHeader5">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="RatingText"
id="viewColumn6">
<xp:viewColumnHeader value="RatingText"
id="viewColumnHeader6">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="RatingNum"
id="viewColumn7">
<xp:viewColumnHeader value="RatingNum"
id="viewColumnHeader7">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="Comments"
id="viewColumn8">
<xp:viewColumnHeader value="Comments"
id="viewColumnHeader8">
</xp:viewColumnHeader>
</xp:viewColumn>
</xp:viewPanel></xp:td>
</xp:tr>
</xp:table></xp:view>
It is possible to add an onClientLoad eventHandler to a viewPanel:
https://xcellerant.net/2013/01/14/viewpanel_onclientload
Clicking a Pager results in the onClientLoad being fired.
Question: is it possible to catch the Page Number of the Pager being clicked?
Add an on click event to every page number within pager in XPage's onClientLoad CSJS code.
Use dojo.query to get all a-tags within pager:
dojo.query('[id$=pagerWithClickEvents] a').forEach(function(entry) {
entry.addEventListener("click", function() {
alert(this.innerHTML);
});
});
This XPage is a working example:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core">
<xp:viewPanel
rows="3"
value="#{view1}"
id="viewPanel1">
<xp:this.facets>
<xp:pager
partialRefresh="true"
layout="Previous Group Next"
xp:key="headerPager"
id="pagerWithClickEvents">
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView
var="view1"
databaseName="names.nsf"
viewName="People">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn
columnName="$17"
id="viewColumn1">
<xp:viewColumnHeader
value="Name"
id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="$16"
id="viewColumn4">
<xp:viewColumnHeader
value="E-Mail"
id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:eventHandler
event="onClientLoad"
submit="false">
<xp:this.script><![CDATA[
dojo.query('[id$=pagerWithClickEvents] a').forEach(function(entry) {
entry.addEventListener("click", function() {
alert(this.innerHTML);
});
});
]]></xp:this.script>
</xp:eventHandler>
</xp:viewPanel>
</xp:view>
I am using this Ext Lib (8.5.2) custom controls viewpanel, pager save state and dyanmic content. Does pager save state works with View panel.
If yes, pls look at my code here. I do not know why it is not working.
I am in the learning curve of xpages.
Thank you in advance.
Jason
This my custom control
<xe:pagerSaveState id="pagerSaveState1" globalRows="true"
for="viewPanel1">
</xe:pagerSaveState>
<xp:this.resources>
<xp:styleSheet href="/tablelayout.css"></xp:styleSheet>
</xp:this.resources>
<xe:dynamicContent id="dynContent" defaultFacet="viewpnl"
useHash="true">
<xe:this.facets>
<xp:panel xp:key="viewpnl" id="viewpnl">
<xp:viewPanel rows="30" id="viewPanel1" var="rowData"
columnClasses="evencol,oddcol" rowClasses="evenrow,oddrow"
binding="#{javascript:viewStateBean.restoreState}">
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next"
xp:key="headerPager" id="pager1">
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view1"
categoryFilter="#{javascript:sessionScope.searchValue}"
expandLevel="1" viewName="#{javascript:viewScope.vName}">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="Urgency" id="viewColumn1"
expandedImage="/Collapse+Icon" collapsedImage="/Expand+Icon">
<xp:viewColumnHeader value="Urgency" id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="From1" id="viewColumn2"
displayAs="link">
<xp:viewColumnHeader value="From" id="viewColumnHeader2">
</xp:viewColumnHeader>
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:executeScript
script="#{javascript:viewScope.docUnid = rowData.getNoteID();}">
</xp:executeScript>
<xe:changeDynamicContentAction
facetName="form1" for="dynContent">
</xe:changeDynamicContentAction>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:viewColumn>
<xp:viewColumn columnName="SubDateTime" id="viewColumn3">
<xp:this.converter>
<xp:convertDateTime type="both" timeStyle="short">
</xp:convertDateTime>
</xp:this.converter>
<xp:viewColumnHeader value="Time of Call" id="viewColumnHeader3">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="Category" id="viewColumn4">
<xp:viewColumnHeader value="Category" id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="JobStatus" id="viewColumn5">
<xp:viewColumnHeader value="Status" id="viewColumnHeader5">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn id="viewColumn6">
<xp:this.value><![CDATA[#{javascript:if (rowData.isCategory()){return rowData.getColumnValue("Total")
}}]]></xp:this.value>
<xp:this.converter>
<xp:convertNumber type="number" integerOnly="true">
</xp:convertNumber>
</xp:this.converter>
<xp:viewColumnHeader id="viewColumnHeader6"
value="Total">
</xp:viewColumnHeader>
</xp:viewColumn>
</xp:viewPanel>
</xp:panel>
<xc:xp_serviceRequestform xp:key="form1"></xc:xp_serviceRequestform>
</xe:this.facets>
</xe:dynamicContent>
This is the form cancel button
<xp:button value="Cancel" id="cancelbut">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" immediate="true" save="false">
<xp:this.action>
<xp:actionGroup>
<xe:changeDynamicContentAction
facetName="viewpnl" for="dynContent">
</xe:changeDynamicContentAction>
<xp:executeScript
script="#{javascript:viewStateBean.restoreState = true}">
</xp:executeScript>
</xp:actionGroup>
</xp:this.action></xp:eventHandler>
I've been following Dave's Notesin9 video on full text searching.
My source code is:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
defaultLinkTarget="_blank">
<xp:br></xp:br>
<xp:inputText id="inputText1" value="#{requestScope.variant}"></xp:inputText>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:text escape="true" id="computedField1" value="#{javascript:requestScope.variant}"></xp:text>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button id="button3" value="Search"><xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true"></xp:eventHandler></xp:button>
<xp:br></xp:br>
<xp:viewPanel id="viewPanel1" pageName="/p_form.xsp" rows="20">
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next"
xp:key="headerPager" id="pager1" style="width:40.0px">
</xp:pager>
<xp:viewTitle xp:key="viewTitle" id="viewTitle1"
value="List of documents"
style="width:153.0px;background-color:rgb(64,128,128);color:rgb(255,255,0)">
</xp:viewTitle>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view1" viewName="vijay"
search="#{javascript:requestScope.variant}">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="name" id="viewColumn1"
showCheckbox="true" displayAs="link">
<xp:viewColumnHeader value="name" id="viewColumnHeader1"
style="background-color:rgb(192,192,192)">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="age" id="viewColumn2">
<xp:viewColumnHeader value="age" id="viewColumnHeader2"
style="background-color:rgb(192,192,192)">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="email" id="viewColumn3">
<xp:viewColumnHeader value="email" id="viewColumnHeader3"
style="background-color:rgb(192,192,192)">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn id="viewColumn4" style="width:89.0px"
displayAs="link" columnName="$6">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header"
id="viewColumnHeader4" value="Attch">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
</xp:viewPanel>
<xp:button value="New Topic" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:openPage target="newDocument" name="/p_form.xsp"></xp:openPage>
</xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:button value="Delete selected" id="button2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:deleteSelectedDocuments view="viewPanel1"
message="Are you sure to delete it('em)?">
</xp:deleteSelectedDocuments>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
here, included a textfield to input the search term,
computed field to view the queried term,
a button labelled search as a submit button.
Entered value in the textfield and
when i press the search button, i get error 500.
Where lies the mistake?
Pls help.
Naveen's almost certainly spot on, that the database is not full text indexed. Check the \data\IBM_TECHNICAL_SUPPORT folder on the server, for the latest modified file starting xpages_exc_###. This will give the full detailed error, including the stack trace. The XPages Log Reader project on OpenNTF can be used to view those files from a browser.
I'd recommend using sessionScope instead of requestScope for the search value. If you use requestScope, it's only available during that partial refresh. So when the user uses a pager or opens a document and goes back to the view, the requestScope variable is null again, so the search criteria are lost.