Fill textbox with current username logged in sharepoint - 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.

Related

How to use an InputBox with a table - Domino Designer

I would like to create a button which then opens an inputbox, the user then inputs a message, and then I would like to create a table with there name & the message in, on the same form.
Is this possible in Domino Designer?
Formula?
LotusScripts?
Not knowing the proper use case, and expecting that more than just one user will be able to click that button for a single document, let me recommend a slightly different solution:
I tend to solve these by using a simple multi value text field, make it computed when composed. Then if a user enters a message I append (or prepend) a new line to the list field like in
[Lothar Mueller, 2015-05-01 15:00:01]: this is my message

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!

Field Validation in EditorGrid

Let's start with saying that I'm using GXT 2.2.5 on GWT 2.3.0.
My goal is to present the user with a set of data retrieved from a query where he needs to specify a value for one of the fields. As an example, let's say the query returns a list of phone numbers, and the user needs to sepcify the type of number (i.e., Home, Office, Cell, or Pager) each is.
So I'm looking at the EditorGrid as a potential solution. The grid would display the type and number, with a ComboBox attached to the first field through a CellEditor.
The requirement is that the user must select a type for each number. How do I enforce this? I can set allowBlank to false on the ComboBox, but how do I manage it? How do I validate the grid?
I've searched for an answer, but have been unsuccessful.
I suggest the use of the Grid, not the EditorGrid. When using a RowEditor within the Grid the allowBlank validation (or any other fields validator) are fired when the user saves row changes.
Here is a little example in case you are not familiar with the Grid:
ColumnConfig colNombre = new ColumnConfig("name", "Name", 200);
TextField<String> txtNombre = new TextField<String>();
txtNombre.setAllowBlank(false);
txtNombre.getMessages().setBlankText("IT CANT BE EMPTY.");
colNombre.setEditor(new CellEditor(txtNombre));
configs.add(colNombre);
re = new RowEditor<BeanModel>();
re.addListener(Events.AfterEdit, new Listener<RowEditorEvent>() {
public void handleEvent(RowEditorEvent e) {
editar(e);
}
});
re.setClicksToEdit(ClicksToEdit.TWO);
grid = new Grid<BeanModel>(STORE, new ColumnModel(configs));
grid.addPlugin(re);
hope it helps.
Have a SimpleComboBox<String> to store all types of numbers (Home, Office etc). Attach it to the EditorGrid. Set the setEditable(false) property for SimpleComboBox<String>, and make sure that a valid "type" is selected by default in the combo-box (using setValue(...)).
In this way, when your Grid gets rendered, the phone numbers will have type beside them, having a default value selected.
I feel that this is a good approach, rather than having combobox with blank value initially, and then asking user to fill it by showing validation error.

Customize Survey fields in Sharepoint 2007

I have a Survey list which has several questions, one of those is people picker field and the another one is single line of text field.
I need to hide a perticular question ( field ) based on login user. Requirement is as below
When the user logs in as admin
a. Display ‘people picker’ and should not allow user to pick his name from people picker.
b. Hide Single line of Text field.
When the user logs in as ‘Non-Admin’
a. Display ‘Single line of Text' field and default it to have the logged in user name (without domain name).
b. Hide ‘People picker’ control.
I am thinking that we can do it by placing javascript in content editor webpart and add it in newform.apx of survey list. Can anybody give me the proper approach to get it done?
Thanks in advance
You might like to try creating a custom field control, a differnet one for each field.
Javascript is fast and involves minimal deployment, but is fiddly and can be turned off.

Sharepoint calculated field's formula for created by

i have a sharepoint list
with 2 users for examole (user A and user B)
i need a calculated field in the list items such that if user "A" created the item the field vaule will be "X" and if user "B" created the item fields value would be "Y"
but i couldnt use [created by] in the furmiula of the calculated field !! why is that ?!! and is there another way to do what i need to do ?!
If using Sharepoint Designer is an option you can create a workflow for that list. Set it to start when a new item is created -or- edited, use a condition of "If Created_By equals ..." and an action of "Set yourfield to yourvalue", then add an Else If branch and repeat. This will always override anything a user enters in "yourfield". Takes about 2 minutes to do all of this.
I believe you can create a text field that has the default value set to [Me] which should then be usable in a calculated field.
For more complicated formulae (i.e. anything with conditional logic), try creating an event handler for the content type (or doc library). This will allow you full control to set the fields to what you desire.
The field can be hidden from the user inside the edit screens.
Make sure use the STSDev from codeplex to setup the solution for deployment.

Resources