Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to add this script (Marc Anderson's blog) to AllItems.aspx. Please guide me where it needs to go and what needs to be done to make it work. Thank you.

<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery.SPServices-0.5.4.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
    var userDepartment = $().SPServices.SPGetCurrentUser({
        fieldName: "Department"
    });
    $("input[Title='Department']").val(userDepartment);
var userPhone = $().SPServices.SPGetCurrentUser({
    fieldName: "WorkPhone"
});
$("input[Title='Phone']").val(userPhone);
});
</script>
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Pop this into the "Edit Source" box within the properties of a Content Editor Web Part, should get it going.

share|improve this answer
    
Hi James. I am running SharePoint Foundation and I don't see the "Edit Source" in the properties box. Can I still access it with Foundation or maybe in SPD 2010 instead? Thank you. –  Anonymous Jul 17 '10 at 20:14
add comment

James is totally correct about how to implement the script into the page, but based on what the script does, I don't think you want it in AllItems.aspx. It looks like you are trying to prepopulate column values on NewForm.aspx or EditForm. You should put the script into the page where you want it to operate.

share|improve this answer
    
Hi Marc. Thank you for the helpful blogs. I am trying to filter a list based upon a value in the User Information List for the current user. I wont be using the fields in the script, just the variable as criteria for the filter. Does SharePoint Foundation allow you to access the "Edit Source" property of a CEWP. Thank you. –  Anonymous Jul 17 '10 at 21:01
1  
Foundation does have "Edit Source" for CEWPs. It is more tricky now. When you are in "Edit Page" mode, thew CEWP on the page will have a link to add content. Click in it, then a rich text box will appear at the top. There is a group at the far right for Markup Styles. Click on the HTML drop down and choose "Edit HTML Source." Note that when you save the source you will get a warning message that the contents of the page changed. That's ok. –  Rob Wilson Jul 17 '10 at 21:44
    
Thanks Rob. I wouldn't have found it other wise. –  Anonymous Jul 18 '10 at 18:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.