How to Sort View control by Lookup column - xpages

I have two forms that are related and I would to combine them in a view control. Not that difficult. This is for a "1 to Many" type scenario.
Say I have a customer view with the columns customerID and Customer Name. Then I have a view showing the "many" documents that has the columns masterCustomerID, orderNumber, orderDate.
On the XPage I create a view control of the many documents and add the columns masterCustomerID, orderNumber, orderDate. Then I add a column in the front to do a DbLookup to pull in the actual name of the customer. Nothing too fancy really.
My question is, in this situation, where the lookup column is the FIRST column. What are the strategies to sort the view column by that column. By default it would sort by the Key Value in the order view which is likely different then the Name values.
I'm not averse to using repeat controls if that would be easier.
My first thought would be to employ TreeMaps somehow, but I don't know if that's practical in the event that there might be a LOT of documents. Maybe there's something I'm missing...
Any advice would be appreciated. Thanks

Use view with (Customer name, Customer ID) structure as main view. Then based on Customer ID populate other columns by lookup from view with structure (Customer ID, Order ID, Order date). Hence it is 1:N relationship, you can't use single view component, but two nested - repeat inside view column would do.
I hope you are aware of performance impact (orders looked up for every customer row), so don't try to show too many customers at once.

Related

Filtering lotus-domino views that have multiple categories and multiple values

I am trying to design a view with multiple categories, and each document can belong to multiple categories at the same time.
For example, File A is in category:
1->a;
2
I can achieve this effect by specifying the columns as categories and access the document through various routes. However, I fail to specify which category the sub-categories belong to. This is what I am getting instead:
1->a;
2->a
The case doesn't seem too big of a difference but basically the view is returning every combination of the categories and the amount of entries can get very large.
I have tried to add the super category in front of the sub-category and try to filter out entries which the categories do not match the prefix of the sub-categories(e.g. 1,a), but I cannot find a way filter them out. Although the multiple values are shown in different entries, when I try to use the variable it extracts all the values.
Is there a way I can filter the entries based on that particular row instead of all the values? Or is there anyway I can achieve the effect through other methods? Thank you in advance.
You need to collapse Categories and subcategories into a single field. The Domino way to do this is to separate category and subcategory by backslash. So your category field would be something like:
"1\a":"2"
That ties the subcategory to the category. Or if you want to be able to find a document by subcategory only:
"1\a":"a":"2"
You then can use a little formula magic to get from the subcategory back to the main category (presuming the subcategories don't duplicate):
AllCategories := "1\a":"a":"2";
foundCategory := "a";
#Trim(#Replace(AllCategories;foundCategory:#Trim(#ReplaceSubstring(allCategories;foundCategory)));
This would return "1\a" (Note: the formula above is written is classic #Formula language, it is left as an exercise to the reader to translate that to the JavaScript formula equivalent)
Hope that helps

Create Notes view for duplicate parent documents

We have an Xpages application and recently discovered an issue where there are several Notes documents that have duplicates but the duplicates are PARENT documents too and NOT response documents. Is it possible to create a Notes view that will show duplicates where all the duplicates are parents? I know the formula for showing conflicts is the following but what about where they are all parents?
SELECT #IsAvailable($Conflict)
Expounding on my comment:
Create a view which is categorized on the first column
In the first column formula, put in criteria that you would use to determine a duplicate. This may be the Document Unique ID, or maybe another field or combination of fields.
Add a second column that contains the number 1. Then enable column totals on this column.
Now look at this view you created. With the view categories collapsed, look for any number greater that 1 to determine which documents are duplicates.
I think what you are asking is not how to identify the duplicates - but how to find out which of them are parent documents. So basically you would create a view as Steve suggests - but instead of putting a constant of 1 into the second column I would suggest putting either #DocChildren (for immediate responses) or #DocDescendants (for all responses and responses to responses).
If I understand your logic then all the ones returning 0 (zero) are child documents and those returning 1 or higher would be parent documents. Of course you could also use an item on the document in your view formula - if it only exists on the parent doc (or its value can tell that it is a parent doc)
View selection formulas act on only one document at a time. They cannot perform lookups. They have no way to compare two documents. There is therefore no possible way for a view to identify duplicates.
A view can, as per the other answers, categorize documents based on common values. If there is a single field that is supposed to be unique across all documents, you can categorize on that field. That will give you a visualization of the duplicates, but it won't filter them in or out.
The only way for a view to filter duplicates - either to show only duplicates, or to exlude duplicates - would be if you run an agent that reads all documents, looks for those that are duplicates, and marks them with a special field value - e.g., IsDuplicate = 1. Once you do that, you can create a view that selects all documents with IsDuplicated = 1, or a view that excludes IsDuplicated = 1.

repeat control from categorized view

I have tried to get the column values in repeat control from Categorized view in xPages,that time i got the column values are coming with single row,and the same row repeated
How to get the column values in "repeat control from categorized view"?
Thanks
I had a situation where I had to drill down from a much larger view and repeated the info back out with the following.
View is categorized in first column by what I'm drilling down by. I achieve this in the XPage/Custom Control by defining the view as a source in the data tab, then select "filter by category name", bind my repeater to that view data source, and compute the value I'm drilling down.
Then in my repeated table, each of my computed fields for each of the column entries read like:
rowData.getColumnValues()[1]
Adjust for your other columns by position with the array modifier after your getColumnValues method. This is not an elegant solution, but worked for my needs. Hope this helps if it's what you're looking for.
[Update]
It's worth noting that doing this can potentially create a memory handle for any DateTime objects which may be returned in the entirety of the getColumnValues method. If you're going to use this approach, I strongly recommend getting a handle on the column values separately, so you can perform a session.recycle(colVals); on them to prevent any memory creep.
[/Update]

Sort Column Total

I have a view with column totals.
What I want is to sort the totals-column in a Xpages-view or repeat-control.
I am able to get the totals to display but cannot sort them.
Any suggestions?
Not very clean. I wouldn't do that in production - for performance reasons - it's a brute force solution, but it should work for fair amount of categories (up to few hundreds).
Assume the view can be used for category lookups (similar to show single category). Then all you need is list of categories in correct order - based on totals and not alphabetical order. Therefore, in first cycle, loop through all categories (use NotesNavigator with cache) and store them as pair of values - (category, totals). It may be Map[String,Double] or Set[Category] where Category is POJO with category and totals attributes. In both cases you will need your own Comparator. If your categories are hierarchical, use only top level category (sorting of tree structure is more complicated).
For example:
Australia (5)
Brazilia (10)
Chile (7)
will sort as
Brazilia (10)
Chile (7)
Australia (5)
Cache this collection in viewScope (assuming totals are "static" for short period of time, user will need to reload the page to get updated data).
Feed this collection to repeater with simple data table (or view or repeater) showing only selected category.
GUI will be a bit odd with pagers (pager for categories and pager for content of category), but you will handle this, I hope.
It's probably better to ask can this type of sorting or resorting be done in Notes rather than can it be done in XPages. If it can be done in Notes then you should be able to do the same in XPages - sometimes automatically.
XPages can only do so much with the view datasource. So if the datasource can't sort the categories by the totals then you won't be able to do this in XPages. At least not out of the box.
You might be able to do something with repeats - doing a lookup of the datasource, retrieving all documents under a certain category that has the highest total before moving on to the next category in the sequence - but it likely to become pretty complicated and not worth it in the end.
Sorry if it's not the answer you're looking for.
I will try to clarify it.
There is an categorized view. Category is for example Company name.
In the view is a column with totals, so the category has also a total.
The wish is that this categorized view will show the company category, who has the highest total at the top of the view, without losing the categorization

Can I create a COUNTIF calculated column in SharePoint?

Is there a way to create a SharePoint calculated column that returns a count of the number of entries in a list? So If I have 3 customers in my list with the company "Starbucks" I'd like the field to return "3"
(Edited some wording for clarity per suggestion from dariom).
You may be able to get what you want with another list using a not-so-well-known variation of a lookup column.
Let's say you have a list called Companies with values in the title column like "Starbucks", "Peets", etc. Now you also have the Customers list you refer to, but the "Company" column is a lookup column pointing to the title column in the Companies list.
You can add a count very similar to what you described to your Companies list. Go to your Companies list, add a column of type "Lookup" referring to the Customers list and you'll notice that in the drop-down area where you define the lookup if you point back to the Customers list, you'll have a new option called "Count Related". This is here automatically because it recognizes that the Customers list has a lookup pointing back to this one. Select that Count Related option and now your Companies list will have a column counting how many customers are associated with that company.
No coding, Javascript hacks, or anything. Just hidden SharePoint auto-magic.
No, I don't think there's a way to do this using the out-of-the-box calculated column.
Some other ways you could accomplish this are:
Create a view for your list that with a group by on the company field and include the total count. This is easiest, but might not be exactly what you're looking for.
Create a custom column type that executes a CAML query to find items that you're interested in. There is a learning curve if you've not done it before and if the list that you're adding this custom column to has lots of rows, you'll be executing a query for each row which is inefficient - it'll be OK for a small number of rows.
Use an event handler on the list that updates a column value each time a new item is added or removed from a list. This is easier, but can also be inefficient if you have a large number of items in your list.
As dariom said (damn my slow typing skills, +1!), only the current row can be operated on with calculated columns by default in SharePoint. There are a couple of documented workarounds involving SharePoint Designer or jQuery, though.
You can get a Count of specific list items in an XSLT Data View
To do this you will need SharePoint Designer.
Right click on your SharePoint List view (ensure the list view contains the field you want to filter by) select convert to XSLT Data View. Then in the Data Source Windows select Data Source Tab and drag and drop the field you want to get a total on for the specific items into where you want it displayed in your XSLT Data View. Click on the numerical value that is showing you should get a lightening bolt icon, select the drop down and choose Count, then select again and choose Filter. Select "Click here to add a new clause" then choose your field name again and enter your unique value as Starbucks and click OK, you can repeat this process for other fields you want the totals on. You will now see the total number of Starbucks items in the list.
I got something similar to work in a way similar to Niall. Basically, I:
Based on the source list, created a Data View Web Part (DVWP) on a "test" web
part page.
Added the footer column, which gives a count.
Set the filter for my conditions (i.e., the items I want to count).
In the code, deleted the recurring items row.
I was left with just the footer, which displayed a filtered count for all the list items. I further customized the footer by taking out the shaded background. Finally, I exported this web part and imported it onto the page where I wanted users to see a total of items in the list (which met the criteria).

Resources