开发者

Custom List form - Autopopulate Manager

开发者 https://www.devze.com 2023-01-04 12:14 出处:网络
I have a Sharepoint 2007 custom list with a column named \'Manager\', to hold the user\'s Manager (single line of text).

I have a Sharepoint 2007 custom list with a column named 'Manager', to hold the user's Manager (single line of text).

When creating a new item I want the NewForm.aspx to autopulate the Manager f开发者_如何学Cield with the user's manager.

I know we can autopulate list form fields using JQuery to access Sharepoint's 'User Information List' exposed as a webservice, as Marc's blog below:

http://sympmarc.com/2010/04/29/populating-a-sharepoint-list-form-with-the-current-user-information/

My problem is the Manager is not stored in the 'User Information List' so I can not retrieve it as above, anyone have any ideas?

Thanks, Nav


It's very easy, you need to declare a "CAMLQuery", "CAMLRowLimit" and "CAMLViewFields" below of "listName", I'll explain this with the next code example:

You can get your CAMLQuery from a view of you list, in sharepoint Designer open a form, I opened the my view list anuncio.aspx and found the next code:

<View Name="your list name">
<Query> 
<OrderBy>
        <FieldRef Name="Title" Ascending="FALSE"/>
</OrderBy>
    </Query>
<ViewFields>
    <FieldRef Name="Title"/>
    <FieldRef Name="Body"/>
    <FieldRef Name="Expires"/>
</ViewFields>
    <RowLimit Paged="TRUE">30</RowLimit>
    <Toolbar Type="Standard"/>
</View>

Then split the query caml in your JavaScript code depends of your needs or query of your view list,

   var fields ="<ViewFields>"+
        "<FieldRef Name='Title'/>"+
        "<FieldRef Name='Body'/>"+
        "<FieldRef Name='Expires'/>"+
          "</ViewFields>";
   var query = "<Query>"+ 
             "<OrderBy>"+
               "<FieldRef Name='Modified' Ascending='FALSE'/>"+
             "</OrderBy>"+
               "</Query>";

After set the CAMLQuery in the variables, modify your script:

    $(document).ready(function() {


       $().SPServices({
         operation: "GetListItems",
         async: false,
         listName: "Your List name",

         CAMLViewFields: fields,
            CAMLQuery: query,   


            completefunc: function (xData, Status) {

             $(xData.responseXML).SPFilterNode("z:row").each(function() {

                var liHtml = "<tr> <td>" + $(this).attr("ows_Title") + "</td> </tr>";


                 $("#tasksUL").append(liHtml);

        });
      }
    });


   });


   </script>
   <table id="tasksUL"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号