Unable to get some user values on a SP2010 new item form

Nov 9, 2012 at 4:20 AM
Edited Nov 9, 2012 at 4:23 AM

Hi, I have a new item form which I want to inject some information into:

Office

Department

User's Full Name

Here's the code i'm using....the only field which is working is Office

 

 

$(document).ready(function() {

	var userOffice = $().SPServices.SPGetCurrentUser({
		fieldName: "Office"
	});
	$("input[Title='Office']").val(userOffice);

	var userBU = $().SPServices.SPGetCurrentUser({
		fieldName: "Department"
	});
	$("input[Title='Business_x0020_Unit']").val(userDepartment);

	var userName = $().SPServices.SPGetCurrentUser({
		fieldName: "Title"
	});
	$("input[Title='Title']").val(userName);

	});


Can anyone see anything obvious? Btw, I've done the 'alert' tests and know that the SPServices scripts are working. If I'm not supplying enough info let me know what you need.

Thanks! Paul

Nov 9, 2012 at 11:57 AM

For the second variable, "userBU", you refer to it as "userDepartment" when you try to write it to the Business Unit field.  That will cause you some pain.  With that one failing, it could be aborting the script because I don't see anything wrong in the 3rd call....but it's early and I've just started my coffee  ;-)

Geoff

Nov 9, 2012 at 1:25 PM

I'm thinking you are confusing static names with display names.  You'll want to use the display names to reference fields on your forms. I'm willing to bet "Business_x0020_Unit" looks like: "Business Unit" on your form.  Change what @gkoliver said to and update to the display names.  That should fix you up.

 

Cheers,
Matthew 

Nov 11, 2012 at 8:16 PM
gkoliver wrote:

For the second variable, "userBU", you refer to it as "userDepartment" when you try to write it to the Business Unit field.  That will cause you some pain.  With that one failing, it could be aborting the script because I don't see anything wrong in the 3rd call....but it's early and I've just started my coffee  ;-)

Geoff

Ah ok, yep that makes sense, I'm not a coder so wasn't quite understanding the convention of the code, but got it now and all queries working fine....thanks guys!