I'm selecting documents in a view by daterange. The start date is alway correct but the end date isn't. The selection goes from the startdate till the last entry.
My code is :
var vDateRange = session.createDateRange(sessionScope.selectedStartDate, sessionScope.selectedEndDate);
var projects:NotesView = database.getView('visits_by_date_VB')
var viewNav:NotesViewNavigator = projects.createViewNav();
var viewEntryCollection:NotesViewEntryCollection = projects.getAllEntriesByKey(vDateRange);
var viewEnt:NotesViewEntry = viewEntryCollection.getFirstEntry();
var output:string = "";
while (viewEnt != null) {
output += "<tr>";
output += "<td>" + viewEnt.getColumnValues()[0]; + "</td>";
output += "<td>" + viewEnt.getColumnValues()[3] + "</td>";
output += "<td>" + viewEnt.getColumnValues()[4] + "</td>";
output += "<td>" + viewEnt.getColumnValues()[5] + "</td>";
output += "</tr>";
viewEnt = viewNav.getNext(viewEnt);
}
EDIT
Picking up dates with following code :
<xe:djDateTextBox id="StartDate"
defaultValue="#{javascript:sessionScope.selectedStartDate}"
value="#{sessionScope.selectedStartDate}">
<xp:this.converter>
<xp:convertDateTime type="date"
dateStyle="full">
</xp:convertDateTime>
</xp:this.converter>
</xe:djDateTextBox>
<xe:djDateTextBox id="EndDate"
defaultValue="#{javascript:sessionScope.selectedEndDate}"
value="#{sessionScope.selectedEndDate}">
<xp:this.converter>
<xp:convertDateTime type="date"
dateStyle="full">
</xp:convertDateTime>
</xp:this.converter>
</xe:djDateTextBox>
First column of the view is a date /time "style" sorted Ascending
The field on the form that stores the dates is a date time field .
Change this one line
viewEnt = viewNav.getNext(viewEnt);
to
viewEnt = viewEntryCollection.getNextEntry(viewEnt);
and it will work.
You initialize viewNav with the complete view content. That's why it starts with the right date from viewEntryCollection but runs always to view's end. You don't need the viewNav in this code and can delete this line.
Related
I have to programmatically set the formula for a calculated field in a list.
This field has to be the sum of two other fields. Can you provide me with the syntax for the formula that I have to insert in the code? I cannot find any example.
Can you provide me also with a reference for formula syntax because I have also to create another calculated field which is the concatenation of two string fields.
Thank you
Calculated Field Formulas reference:
For your task use simply:
=[Column1] + [Column2]
Create Calculated field with server code reference
using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Website_Name"])
{
SPList oList = oWebsite.Lists["MyList"];
SPFieldCollection collFields = oList.Fields;
string strNewFieldName = collFields.Add("MyNewColumn",
SPFieldType.Calculated, false);
SPFieldCalculated strNewField =
(SPFieldCalculated)collFields[strNewFieldName];
strNewField.Formula = "=[Column1]<[Column2]";
strNewField.Update();
}
Create Calculated field with CSOM code reference1, reference2. As you see below you need to remeember about escape special characters in xml.
string formula = "<Formula>=FirstName& \" \" &LastName& \" (id: \" &EmployeeID& \" \"</Formula>"
+ "<FieldRefs>"
+ "<FieldRef Name='FirstName' />"
+ "<FieldRef Name='LastName' />"
+ "<FieldRef Name='EmployeeID' />"
+ "</FieldRefs>";
string schemaCalculatedField = "<Field ID='<GUID>' Type='Calculated' Name='FullName' StaticName='FullName'
DisplayName='Full Name' ResultType='Text' Required='TRUE' ReadOnly='TRUE'>" + formula + "</Field>";
Field fullNameField = demoList.Fields.AddFieldAsXml(schemaCalculatedField, true, AddFieldOptions.AddFieldInternalNameHint);
clientContext.ExecuteQuery();
Working code for your implementation (comments):
string formula = "<Formula>=Nome1&" "&Cognome1&"(id:"&Campo1&")"</Formula>" + "<FieldRefs>" + "<FieldRef Name='Nome1'/>" + "<FieldRef Name='Cognome1'/>" + "<FieldRef Name='Campo1'/>" + "</FieldRefs>";
string schemaCalculatedField = "<Field ID='1F2ABCC0-D243-40F0-A18D-E0AEF7FE3EB6' Type='Calculated' Name='FullName' StaticName='FullName' DisplayName='Full Name' ResultType='Text' Required='TRUE' ReadOnly='TRUE'>" + formula + "</Field>";
Field fullNameField = context.Web.Lists.GetByTitle("PnP Custom List3").Fields.AddFieldAsXml(schemaCalculatedField, true, AddFieldOptions.AddFieldInternalNameHint);
context.ExecuteQuery();
I have a button that exports a view to Excel from an Xpage. It works fairly well, but when the user opens up Excel there are no grid lines and I know they are going to freak out. I have looked for an hour on the internet for how to turn these one but I can't find how.
Does anyone know how to do this?
Here is my code"
var output:string = "";
for(i=0;i < sessionScope.searchDocIDArray.length; i++)
{
var docId=sessionScope.searchDocIDArray[i];
var doc=database.getDocumentByID(docId);
output += "<tr>";
output += "<td>" + doc.getItemValueString("user") + "</td>";
output += "<td>" + doc.getItemValueString("loc") + "</td>";
output += "<td>" + doc.getItemValueString("date") + "</td>";
output += "<td>" + doc.getItemValueString("workCategory") + "</td>";
output += "<td>" + doc.getItemValueString("state") + "</td>";
output += "<td>" + doc.getItemValueString("timeSpent") + "</td>";
output += "<td>" + doc.getItemValueString("notes") + "</td>";
output += "</tr>";
}
facesContext.getExternalContext().getResponse().setHeader("Content-disposition", "attachment; filename=TSC Time Spent.xlxs");
facesContext.getExternalContext().getResponse().setHeader("Cache-Control", "no-cache");
facesContext.getResponseWriter().write("<x:WorksheetOptions>")
facesContext.getResponseWriter().write("<x:Panes>");
facesContext.getResponseWriter().write("</x:Panes>");
facesContext.getResponseWriter().write("<x:WorksheetOptions>")
facesContext.getResponseWriter().write("<table><thead><tr><td><b>User</b></td><td><b>Loc</b></td><td><b>Date</b></td><td><b>Work Category</b></td><td><b>Time Spent</b></td><td><b>Notes</tr></thead>"+output+"</table>");
facesContext.getResponseWriter().endDocument();
One way to make sure grid lines are intact is to export to csv instead of using html tags to write out your content.
You also can assign css to your to td elements but the borders will not look like they do natively in excel.
Here is an example of using csv. This is a simplified version of something I used in afterRenderResponse:
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var output = "";
var colHeaders = "col1,col2,col3,col4,col5";
// Loop through data set
while (doc != null) {
output+="\"" + val1 + "\",";
output+="\"" + val2 + "\",";
output+="\"" + val3 + "\",";
output+="\"" + val4 + "\",";
output+="\"" + val5 + "\",";
output += #Char(13)+#Char(10); // start a new row
}
response.setContentType("application/csv-tab-delimited-table;charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition", "attachment;filename=actionExport.csv");
writer.write(colHeaders+#Char(13)+#Char(10)); // Add the first row as column titles and add line feed
writer.write(output+#Char(13)+#Char(10)); //
writer.endDocument();
It's going to take a bit more investigation, but I would recommend looking at using Apache POI for writing to Excel. It won't throw security alerts with Excel 2007+ like the table approach does. It has more specific APIs for setting styling. The HSSF classes are the ones you want (standing for Horrible SpreadSheet Format!).
Try adding this :-)
<x:WorksheetOptions>
<x:DisplayGridlines/>
</x:WorksheetOptions>
I made an xpage element for ftsearch using a tutorial from IBM
My request: is there possible having 2 date fields ( as input requirements for the search ) to find those documents having the creation date inside the interval consisting of those 2 dates?
Should I create a computed field dtCreated where I will store the creation date and then in the search property of the view I should add something like this:
var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
tmpArray[cTerms++] = "(Field dtCreated > \"" + sessionScope.searhcDate1 + "\")" && "(Field dtCreated < \"" + sessionScope.searhcDate2 + "\")";
}
....
....
Or there is another alternative?
My 2 session variables are having Short (5/5/14) Date format. Also, my default value for those 2 dates (session variables) are "" but of course I add some values before clicking the Submit button.
Thanks for your time!
You can use the special field _creationDate as creation date (see answer from Tommy). Based on this the following example query will work in the Notes client:
Field _creationDate > 01-01-2014 AND Field _creationDate < 01-03-2014
In order to get this query to work with your specific code do this:
var tmpArray = new Array("");
var cTerms = 0;
var dateFormatter = new java.text.SimpleDateFormat( "dd-MM-yyyy" );
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
tmpArray[cTerms++] = "Field _creationDate > " + dateFormatter.format(sessionScope.searchDate1) + " AND Field _creationDate < " + dateFormatter.format(sessionScope.searchDate2);
}
If you want to do an FTSearch, _CreationDate can be used
Documentation (scroll to Searching for Header Information):
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.main.doc%2FH_CUSTOMIZING_SEARCH_FORMS_7304.html
E.g. (there might be typos):
tmpArray[cTerms++] = "(Field _creationDate>" + sessionScope.searhcDate1 + ") AND (Field _creationDate<" + sessionScope.searhcDate2 + ")";
Or my preferred syntax:
tmpArray[cTerms++] = "[_creationDate>" + sessionScope.searhcDate1 + "] AND [_creationDate<" + sessionScope.searhcDate2 + "]";
To build on Tommy's answer:
Specifically, try "yyyy/m/d" as the format. If those values in sessionScope are java.util.Date (the type that date fields use), you could try something like this (typing off the top of my head, not in an app, so my apologies for typos):
var tmpArray = [];
var cTerms = 0;
if(sessionScope.searchDate1 && sessionScope.searchDate2) {
var formatter = new java.text.SimpleDateFormat("yyyy/M/d");
tmpArray[cTerms++] = "[_CreationDate] >= " + formatter.format(sessionScope.searchDate1) + " and [_CreaationDate] <= " + formatter.format(sessionScope.searchDate2)
}
What you want to end up with is a FT query like:
[_CreationDate] >= 2014/1/1 and [_CreationDate] <= 2014/2/1
I created an XPage and added a view control to it, based on a Notes view in which some of the columns are based on formulas rather than fields (for example, #If(nomprov="";cifprov;nomprov)). As a result, the column name on the XPage is a number preceded by a dollar sign, such as $14. View columns that are field based do not show such behavior (the column name on the XPage is the name of the field).
This did not harm on any way, but now I am trying to implement full-text search on the XPage view, and the search on $* columns is not working. This is the definition of one of these columns on the page source:
<xp:viewColumn id="viewColumn3" styleClass="columna"
columnName="$14">
<xp:viewColumnHeader value="Proveedor"
id="viewColumnHeader3" styleClass="cabecera" sortable="true">
</xp:viewColumnHeader>
</xp:viewColumn>
And this is the code I have on the property data\data\search of the view:
var qstring;
if (sessionScope.searchNumfac != null & sessionScope.searchNumfac != "") {
qstring = "(Field numfac = *" + sessionScope.searchNumfac + "*)"
+ " OR (Field nomsociedad = *" + sessionScope.searchNumfac + "*)"
+ " OR (Field $14 = *" + sessionScope.searchNumfac + "*)";
}
sessionScope.queryString = qstring;
return qstring
Where searchNumFac corresponds to the value on the search box. The search on columns "numfac" and "nomsociedad" works great, but it fails on the $14 column. I also tried changing the $14 on the code by the column title on the Notes view (proveedor) and the column title on the XPage view (Proveedor), but it is still not working.
Do you know of any way to work around this?
Thanks a lot,
Carlos
View columns are not part of full text index. You have to use field names for your full text search.
In your example it means that instead of $14 you have to use the fieldnames from your column formula #If(nomprov="";cifprov;nomprov)):
...
+ " OR (Field nomprov = *" + sessionScope.searchNumfac + "*)"
+ " OR (Field cifprov = *" + sessionScope.searchNumfac + "*)";
Pagination (Next button) doesn't work for custom BusinessDataListWebPart.
I am adding BusinessDataListWebPart using code. Everything works fine. I can see 20 data raw at the same time but when I click "Next Button", I can not see next 20-40 data. A postback occurs, but the pageindex never changes.
I am using following code to add BusinessDataListWebPart to the Sharepoint site.
BusinessDataListWebPart consumer = new BusinessDataListWebPart();
consumer.Title = title;
consumer.Application = instance.Name;
consumer.Entity = projEntity.Name;
consumer.XslLink = "/Style%20Library/XSL%20Style%20Sheets/" + xslFileName;
consumer.PageSize = 20;
OK..I found the answer.
For pagination I needed to add "ParameterBindings" to the business data list webpart.
My final code is, It works perfect.
BusinessDataListWebPart consumer = new BusinessDataListWebPart();
ServerContext serverContext = ServerContext.GetContext(site);
SqlSessionProvider.Instance().SetSharedResourceProviderToUse(serverContext);
LobSystemInstance instance = ApplicationRegistry.GetLobSystemInstanceByName(applicationName);
Entity projEntity = instance.GetEntities()[entityName];
consumer.Title = title;
consumer.Application = instance.Name;
consumer.Entity = projEntity.Name;
consumer.XslLink = "/Style%20Library/XSL%20Style%20Sheets/" + xslFileName;
consumer.PageSize = 20;
consumer.ParameterBindings = "<ParameterBinding Name=" + "\"dvt_firstrow\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_sortdir\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_sortfield\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_filterfields\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_partguid\"" + " Location=" + "\"Postback;Connection\"" + "/>";