Dropdown field sending null on form submission

Feb 20, 2013 at 1:45 PM
Hi Marc. Thanks so much for your hard work. I'm creating a Work Order form for staff to submit help desk issues to our IS dept. In the form, I have a 'Requester' lookup field (from User Information List) that I am able to pre-select with the logged in user's name using your SPGetCurrentUser() function. That part works great! I can even set the field ControlMode="Dsiplay" so they can't chaneg the selection.

My issue is that when the form gets submitted, it seems to be submitting a 'null' or blank to the Requester field in the list. Its showing blank for every new record. Here is the code I've embedded into my NewWorkOrder.aspx code right after the <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> tag...
<script language="javascript" src="/SiteAssets/jquery.min.js" type="text/javascript"></script>
<script language="javascript" src="/SiteAssets/jquery.SPServices.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {  
var userFullname = $().SPServices.SPGetCurrentUser({  
fieldName: "Title" 
});  
$("input[Title='Requester']").val(userFullname);  
});
</script>
Thoughts as to why the pre-selected user's name is not being submitted to the list?
I look forward to your reply.
Thanks!

Mark
Feb 20, 2013 at 3:49 PM
I have a 'Requester' lookup field (from User Information List) that I am able to pre-select with the logged in user's name using your SPGetCurrentUser() function. That part works great! I can even set the field ControlMode="Dsiplay" so they can't chaneg the selection.
Do you think it has to do with what you are doing here? If you make the control display only, you can't change it using any other method... However, you can use Javascript to toggle the control from disabled and enabled. That may make your goal a lot easier over the long run.

Cheers,
Matthew
Feb 20, 2013 at 4:46 PM
Excellent suggestion. I've tried it both ways (ControlMode="New" and ControlMode="Display") but neither will submit the value that is set in the dropdown to the list. I'm trying it out using a People Picker instead of a lookup dropdown field and using SPGetCurrentUser() on the People Picker as described in Tanveer Khan's blog post (http://tanveerkhan-sharepoint.blogspot.ca/2011/09/populate-current-logged-in-user-name-in.html?showComment=1361374050955). I'll let you know if it works.

Thanks for the reply Matthew.
Coordinator
Feb 22, 2013 at 4:28 PM
Mark:

I would definitely recommend a People Picker over any other control.

The way I would do things (based on the little I know about your goals) is to leave the form alone server side and simply hide the table row which contains the People Picker. You can use SPfindPeoplePicker to set it, and the user will not be any wiser.

Of course, that same value will be available in the author (Created By) column, so you may be doing redundant work anyway.

M.
Feb 22, 2013 at 6:22 PM
Edited Feb 22, 2013 at 6:25 PM
Thanks Marc. I did get it working and submitting properly using the People Picker just yesterday. Sorry I didn't get a chance to update this thread. I am using a modified version of the NewForm.aspx for our staff to submit their own Help Desk tickets to us but allows us to select a user from our global address list when we create a new ticket (and stamps which IT staff created the order in the 'Created By' field) using the default form. The customized form will automatically fill the 'Requester' field with a logged in user's info when they go to submit a ticket to us.

As a bonus, it improved my overall design because it allows IT staff to pick a requester from our entire AD versus only being able to select people from the User Information List (ie only staff that have been logged into Sharepoint) that I was using to populate the 'Requester' lookup field .

Currently, the People Picker field is visible to the end user on the customized form.

Any suggestion or code on how I can 'hide' the People Picker from the user but still have it pre-populate and submit to the list upon submission?

Mark
Coordinator
Feb 22, 2013 at 7:01 PM
Edited Feb 22, 2013 at 8:08 PM
Mark:

You can do something like this:
$("nobr").filter(function() {
  // Ensures we get a match whether or not the People Picker is required (if required, the nobr contains a span also)
  return $(this).contents().eq(0).text() === "YourColumnName";  
}).closest("tr").hide();
I've simply taken the code I use to find a People Picker in the page in SPServices and hidden that row. A hidden element is still saved; a disabled one is not.

M.
Feb 22, 2013 at 7:56 PM
Thanks again Marc. I will try this out and let you know how it goes. Have a great weekend!
Feb 25, 2013 at 5:13 PM
Happy Monday! That snippet works perfect! Here's the full snippet that sets the value, hides the field in the form and allows the data to be submitted to the list. Thanks again!
<script language="javascript" type="text/javascript">

$(document).ready(function() {  

var userFullname = $().SPServices.SPGetCurrentUser({  

fieldName: "Title" 

});  

$("textarea[title='People Picker']").val(userFullname);
$("div[title='People Picker']").text(userFullname);

$("nobr").filter(function() { 
// Ensures we get a match whether or not the People Picker is required (if required, the nobr contains a span also) 
return $(this).contents().eq(0).text() === "Requester"; 
}).closest("tr").hide();

});

</script>