javascript脚本查询当前用户的经理manager

直接放代码了,可以先用普通的rest工具查询看看结果再决定使用什么字段,我这里是读取上级经理

<script type="text/javascript"  >
  1. $(document).ready(function(){
  2. $.ajax({
  3. url: _spPageContextInfo.webAbsoluteUrl+"/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=UserProfileProperties",
  4. type: "GET",
  5. headers: { "accept": "application/json;odata=verbose" },
  6. success: function(data){
  7. for(i=0; i<data.d.UserProfileProperties.results.length; i++){
  8. if(data.d.UserProfileProperties.results[i].Key=="Department"){
  9. $("#ctl00_ctl40_g_13f04e09_d97a_4c05_b16d_51e8765d9844_FormControl0_V1_I1_T2").val( data.d.UserProfileProperties.results[i].Value );
  10. }
  11. }
  12. },
  13. error: function(){ console.log('error'); }
  14. });
  15. });
  16. </script>

这个代码适合Sharepoint 2013使用,对于sp 2010或office 365可能无法使用哦!

发表评论