XPages: DropDown selection of documents - xpages

I have a VERY general question and am not 100% sure if I am just being lazy or what, I just cannot seem to get a handle on where to start :o)
I am new to XPages programming and have created an application that works well enough, the problem is that I would like to UI to be totally different to what I have. I find that my implementation is much too "Notes like" and not "Web like" enough. OK, enough whining - I have a document that contains a county, a province, a city and some text to that particular city. Currently I display a view (XPage) listing all documents by county / province / city. The user then selects the city document which is then opened to display the text. Works well enough. As you can see very "Notes like". What I would like is this: The user sees 3 drop down fields (two of which cannot be selected), s/he then selects the country from the drop down. The province field now becomes active only displaying the provinces for that Country. S/he selects the province and all the cities are now is the next drop down - once you select the city the text is displayed below the city name. Quite simple I thought - now matter what I do I cannot get this to work :o(
Any pointers (maybe an example app somewhere?).
Thanks in advance
Greetings
Ursus

First thing you should do is get a copy of the Mastering XPages book and read through that. Then you should look at how rendering and partial refreshes will help you do what you want.
You are going to want to set the rendering to false until you enter some value in the previous field. Then, in the event, you determine if the value is valid and set a flag (could be a simple viewScope) and do a partial refresh of the next field. In that field's properties, you check the viewScope flag that you just set in the previous field and if it is correct, you reset the rendering to true to show the field.

We have implemented exactly that kind of feature on the homepage of ilsschools.co.uk using client side onchange event:
var com2 = XSP.getElementById("#{id:comboBox2}");
XSP.partialRefreshGet("#{id:comboBox2}",
{ onComplete : com2.selectedIndex = 0 });
We get the element we want to refresh (i.e. comboBox2 and we do this for comboxBox3, 4 etc as well). Then we use partialRefreshGet to refresh the choices in comboBox2, this can be repeated for 3, 4 and other comboBoxes as well. You can compute the disabled property of a comboBox to disable it. You can compute the selections for a comboBox using SSJS.
Hope this helps.

Related

Are there any negative consequences of giving ‘Title’ field a default value of ‘View’ and making it a hidden field?

When I create a list, I have gotten into the habit of doing the following:
Change Title field name to Item
Give it the default value of View
Go to Advanced Settings
Allow management of content types > Yes
Click Save
Then in Settings, click on the Item type
Then click on the Item field and select Hidden
Then go back to Advanced Settings
Allow management of content types > No
Click Save
The result of this is that:
The Title field (now called Item) is hidden in the form
I have a column called Item, which has the link View in each row (which opens up the item)
I can’t remember why I started doing this (possibly one of the reasons outlined in this video), but the use case must have demanded it and I just kept doing it.
However, lately I have been having troubling thoughts about whether it negatively effects indexing or has any other undesired outcomes.
For example, I did a search in a list the other today, and in the drop down search results that were displayed, I just got multiple rows of the value View.
I also read just before posting this question that list items in the recycle bin will be identified by the value that was in the Title column. So if they all say View it will be impossible to differentiate one from the other.
So I just thought I would see if there is any authoritative, definitive best practice around the Title column, and ask if my convention is bad and if so what I should replace it with.
Thank You.
(Edit: I also hide the Title column in document libraries, as it doesn’t seem to serve a purpose, as clicking on the value in the Name column opens up the document anyway - therefore the ‘link’ action of the Title field is not required).

Comparing users from #username and #picklist

I have formA where I have "_reviewer" field, which is text/editable. The field is populated when the save button is clicked, the button has the following code:
pick := #Name([CN];#PickList( [Name]));
#SetField("_reviewer"; pick );
#If(#Command([FileSave]);
#Do(
#MailSend(pick;"";"";"Subject";"Body";"";[IncludeDoclink]);
#Command([CloseWindow]);
#StatusBar("Success.")
);
#StatusBar("Fail!"));
I have viewA where document should be shown if the current user is the same as the person in '_reviewer' field, the code in View Selection is:
LCName := #LowerCase(#Name([CN];#UserName));
LCPeople := #LowerCase(_reviewer);
SELECT form = "formA" & (#Contains(LCPeople; LCName))
I have another viewB, where I can see all documents, and one of the columns is '_reviewer'. Now the issue is, even though on viewB I see that John Doe is reviewer for a documentA, the documentA is not shown in viewA when John Doe is logged in as the current user. The tricky part is, documents sometimes show up in viewA, and sometimes they don't, even though I repeat the same steps when creating the document. Having this behavior is unacceptable. Is there some other way to parse the current user and the user picked from #PickList, or some other way to check if the two are the same?
Use an embedded view in a Page like suggested in your last question. This time first categorized column would be #LowerCase(_reviewer) and "Show single category" would have formula #LowerCase(#Name([CN];#UserName)). The view selection is SELECT form = "formA".
You can't use user specific functions like #UserName in public view's selection formula.
Also note, that the user can save the document by pressing Ctrl+S or by closing the window and selecting Yes when prompted. They don't have to use your Save button. If there's really something that must happen before the document is saved, it must be done in the form Querysave event. If it has to happen after the document is saved, it must be in the Postsave event. Kudos for checking the return value of the save command though!

checking if current user is author of the document

I have a formA where I have a field '_author' which is of type Authors/Computed for display with value (#Subset($Updatedby;1)). I display information from formA on viewA. What I want to achieve is that documents that are created by you are only visible to yourself on viewA. I tried the following formula in viewA 'View Selection':
SELECT (form = "formA" & #UserName =_author). Even though I know that these two variables have the same values when I read it from the document's properties, the condition is not satisfied and I do not see a single document. If I delete everything after "&", the view shows all documents.
All is hosted on a server which handles users.
A handy workaround is to create a Page with an embedded view. This view is exactly like your view but has an additional first categorized (!) column with your field _author.
Put into embedded view's property "Show single category" the formula #UserName or #Name([CN]; #UserName) depending on how your categorized column _author is formatted. Show then always the Page instead of the view.
This way you avoid trouble with "Shared, private on first use" views and users see exactly their own documents only.
#UserName works in a special manner in selection formulas in views. In your case the view should be Private on First Use. Read further here: http://www-01.ibm.com/support/docview.wss?uid=swg21089773 .
Be aware that this lead to all sort of issues, e.g. when you update the design of the view users must remove the view manually to get the changes deployed.

Infopath Newbie - Populate field from lookup value

There are explanations for this all over the web, but none I have followed a) seem to work, b) explain how to achieve this in simple noob terms, c) show any sort of diagram, or d) make assumptions that you want to start jumping right into code...
I have a form for users to log training they have completed. I have a sharepoint list with the course name and the duration in hours.
When the user opens the infopath form, it populates a read-only field with their username, and populates a dropdown with the list of available training courses from my sharepoint list.
All I want to do is to populate another read-only field with the duration of the course... But I just cant find the right filter settings to do it.
Currently I have the default value of the duration field in my form set to the formula:
Duration(from SP list)[Course Title (from SP list) = Training Course (from form lookup field)]
But this is not returning any values...
This is using both SP 2010 and IP 2010
Ok, you use rules, not the default value, as pretty much every website I have looked for answer tells you...
Make sure the default value for the field you want to populate is blank, and then set a rule that when your lookup field value changes, it updates the value in your other field...
That was easier than I thought!
This is soemthing called a cascated drop down there are various examples of this on the web.
To do this you need to click on the drop down box that you want to filter.
This will be the duration. (The user would then select the course they went on)
In the duration drop down below you would ensure that you have connected it the correct data source.
Right click on the duraction drop down.
Drop down list properties
get choices from external data source
on the entries you would select the button to the right hand side
You would select 'course title now as this is what you want it to be filtered by' (drop down above)
When selected you would click filter data - (button on bottom right hand side)
You would then filter it so the formula is 'CourseTitle(above drop down) 'is equal to' CourseTitle(data source from the list)'
This then should only allow them to match select the time that matches that course.
If this doesnt work let me know.

XPages - populating multiple fields on typeahead selection

This might be a straightforward question but I can't see wood for trees at the moment
Problem: I have a typeahead attached to an edit box that looks up values from a view (based on Tim Tripcony's code). When a value is selected, I want other edit boxes on the XPage to be populated with values pulled from the corresponding document.
As an example: A username edit box has a typeahead looking up from the NAB. I select "Joe Bloggs" name from the typeahead list and want the email, phone and location edit boxes to be immediately populated with the values from his NAB entry.
I'm banging my head on the wall over this because I'm sure there's an easy and obvious solution. Thanks.
Selecting a value from the typeahead should trigger any onChange event defined for the edit box. You can set the other fields by updating the data source directly from within that event:
var selectedName = currentDocument.getValue("contactName");
currentDocument.setValue("emailAddress", getEmail(selectedName));
currentDocument.setValue("phoneNumber", getPhone(selectedName));
currentDocument.setValue("location", getLocation(selectedName));
Naturally, the above example assumes those are your field names, and that you have the named functions defined elsewhere.

Resources