0
votes

(Please note, before I ask the question in this post, I've found some similar posts in this site. However I cannot ask in those posts by add comment so I decide to ask here. If my question is not appropriate to post, I should be grateful if the administrator would help to remove it please. Thank you.)

In the application, when the user logins to the page, the sessionScope variable will store the user information such as officer name and the department. There is a button for the user to export the data to excel. The report should include the total of the document that the officer has published.

I found this solution in this post export data from panel is useful and gives me the idea how to export data to excel.

I get the code from the post and try to modify it to suit my case. Base on the code, I can preset the value in the report. However, I don't get the idea how to get the total of the document that the officer has published.

I searched on the web, there may have information for me to solve the problem. But I think I misunderstand the information and I don't know which part I did incorrectly.

I would post the code here and seek for your advice please.

Please note, the most of the code is from the solution of this post export data from panel and I would post the code that I guess it is the reason that I don't get the total in the report.

while (viewEnt != null) 
{   
  if(viewEnt.getColumnValues()[1] == officer) //show the record the related to specific officer
  {
    writer.write("<tr>");
    writer.write("<td>" + viewEnt.getColumnValues()[6] + "</td>"); //show document name
    writer.write("<td>" + viewEnt.getColumnValues()[5] + "</td>"); //show document type
    writer.write("<td align='left'>" + viewEnt.getColumnValues()[4] + "</td>"); //show publish date
    writer.write("</tr>");  
  }

var tmp = vec.getNextEntry(viewEnt);
viewEnt.recycle();
viewEnt = tmp;
}
var officer = sessionScope.Officer;
writer.write("<tr></tr><tr><td>Document published </td><td>" + officer.getCount() + "</td></tr>"); //<--cannot get to the total depends on which officer
//also tried officer.getRowCount() but not work
writer.write("</table>");
writer.endDocument();

Also I would like to know is it compulsory to have a column that is categorized in the view in order to get total?

I created two views, one view that the officer column is categorized and the other view is not categorized and use sort ascending. I applied the code and still not get the total that related to the user.

Would someone let me know my mistake please? Thank you.

Reference:

https://www-10.lotus.com/ldd/ddwiki.nsf/dx/notesxspviewentry_sample_javascript_code_for_xpages

https://www-10.lotus.com/ldd/ddwiki.nsf/dx/NotesViewEntry_sample_JavaScript_code_for_XPages

How to get Categorizied Column Totals into an XPageTotal Value from View column

Get entries count for a multiple category view (two categories) using a key (Xpages)

Getting a summary count in a view export?

1

1 Answers

1
votes

Nothing is XPages specific in what you need to do. You loop through a collection and need the total. Add

    var total = 0;
    while (viewEnt != null) {
       total += 1;   
       ...
    }
    writer.write("<tr></tr><tr><td>Document published </td><td>" + total + "</td></tr>);

If you need the total from a column value use the same approach but instead of 1 use the column value.