Comparing users from #username and #picklist - lotus-notes

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!

Related

Powerapps: button selection on a previous screen prefill a field in a form

I am attempting to build an app with Microsoft powerapps that will be writing/reading data to/from an excel sheet.
I have created a form in powerapps from a table in the excel sheet. I am curious to know if anyone knows how to fill the data in a field based on a button selection on a previous screen.
As an example let's say the following fields are in the form; Location, Action, Item, Username.
This is what I am imaging and would like to do;
I would like the first two fields to be filled by selecting buttons on a previous screens instead of a drop down menu in the edit form view. the last two field can be filled by inputting text on a thirds screen.
The flow:
Screen1; presents two 4 locations in the form of buttons*doesn't necessarily have to be a button but function like one.
4 locations: NY, LA, AZ, LN
when users selects "NY" button, "NY" is filled/stored in to the "location" field in the form and the screen navigates to the next page where the user will select the actions.
Screen2; presents two 2 actions in the form of button.
2 Actions: remove, add
when users selects "remove" button, "remove" is filled/stored in to the "action" field in the form and the screen navigates to the next page where the user will fill the other two fields in a text field.
Screen3; has two text fields where user can fill in the rest of the information for item and user name. Location and Action should be prefilled at this point. When the user submits the form all data is submitted and a row is created in the excel table with all the information captured.
any information how to make a button selection on a previous screen prefill a field in a form that would be awesome! thank you for reading.
It sounds like you want to use a collection. A collection can be used similar to a global variable and will allow us to access data on a different screen than the one we set it on.
Some useful information can be found here:
https://powerapps.microsoft.com/en-us/tutorials/working-with-variables/#create-a-collection
https://powerapps.microsoft.com/en-us/tutorials/function-clear-collect-clearcollect/
Based off of your flow, let's assume that the screens are named as follows:
Screen1 will be "SpecifyLocation"
Screen2 will be "SpecifyAction"
Screen3 will be "FinalizeInput"
The names are arbitrary, but I think they'll make the following example easier to follow.
On the screen "SpecifyLocation", we're going to create four buttons. They will all be identical, except for the name of the location they reference. For instance, the button referencing "NY" would be as follows:
Text = "New York"
OnSelect = ClearCollect( LocationMetadata, "NY" ); Navigate(SpecifyAction,ScreenTransition.Cover)
Please note that the OnSelect value is two different functions separated by a semicolon. The first function, ClearCollect(), clears all information in a collection and then writes a new entry. In this case, we have a collection named LocationMetadata into which we are writing the value "NY". The second function, Navigate(), changes which screen we are looking at.
On the screen "SpecifyAction", we're going to create two buttons. They will be similar, except for the action they refer to. For instance, the button referencing "Add" would be as follows:
Text = "Add"
OnSelect = ClearCollect( ActionMetadata, "Add" ); Navigate(FinalizeInput,ScreenTransition.Cover)
As was the case before, we've created a button that calls two functions when clicked. They are the same two functions as last time; however, we've changed LocationMetadata to ActionMetadata in our ClearCollect() call, since we want to store a different piece of information. We've also changed our Navigate() call to move us over to the "FinalizeInput" screen.
I'm not entirely sure how you've got your final screen laid out, but in any case, you'll want to access the data we stored in collections previously. This can be done with the function First(), which returns the first element of a collection.
To access our selected location, you can use: First(LocationMetadata).Value
To access our selected action, you can use: First(ActionMetadata).Value
You should be able to supplement whatever extra data is collected from your user on this final screen with the collections we set up.

"Like" button for a database in Lotus Notes

Is there a way to implement a "Like" button for a database in Lotus Notes. I basically want to have a document in Notes, where is will be possible to click a button and its then liked.
At the moment I have a button but it can be pressed as many times as they want. If possible I would like to be able to only click it once?
Instead of counting the "likes", or incrementing a counter each time the button is pressed, instead save the current user's name to a list and then count the number of users in that list to tell you the number of likes.
On click this would be roughly:
ListOfLikes := #Unique(ListOfLikes:#UserName);
And then to display the count:
#Count(ListOfLikes)
Adding to #Ken's answer, you could use a pair of buttons for "Like" and "Unlike" with hide-when formulas. For the paragraph containing the Like button
!(#Username = ListOfLikes);
For the paragraph containing the Unlike button
#Username = ListOfLikes
(You don't need to use #IsMember for this, as comparing a scalar string against a list works the same way.)
The formula for the actual Unlike button would have to remove a name from the list, like this:
#Trim(#Replace(ListOfLikes;#Username;""));

XPages: DropDown selection of documents

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.

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.

Fill textbox with current username logged in sharepoint

I made a custom list, it is actually a form fill out for an absence request workflow. Before publishing it I found a flaw.
The first textbox is a Person or Group textbox, this helps out to retrieve the Active Directory username, but the flaw is that I can type whatever username I want, Example:
"User X is logged on, but if he types User Y and hits enter he can request an absence for User Y"
So what I want is, hide the textbox and fill it automatically with the current logged on user.
I've been looking for formulas for the calculated textboxes but I haven't found anything.
I´m not exacly sure what you wan´t to do here but if you have a peoplepicker that you want to fill with the current user, here is how to do that. Then you would have to disable the control in order for the user not to be able to change the value in it.
PickerEntity entity = new PickerEntity
{
Key = SPContext.Current.Web.CurrentUser.LoginName
};
PeopleEditor.Entities.Add(entity);
PeopleEditor.UpdateEntities(PeopleEditor.Entities);
Does this help?
SPUser user = SPContext.Current.Web.CurrentUser;
If you want the current logged in user, just use the Created By field in the list. This column is automatically populated with the user who created the item.
Try SharePoint Designer WF that takes Created By and sticks it in that field.
Or, hide the column using jQuery and just have it populate by using the default value of the field as [ME]. [ME] fills in the textbox with the currently logged in user.
Edit: This whole thing could be dealt with by just grabbing the Created By in the workflow. You don't even need to capture the value in a textbox. SharePoint knows who created the item already. This will actually result in a less complicated form.

Resources