2014-09-17 3 views
0

Sharepoint 목록의 마지막 수정 시간을 가져 오려고합니다. 저자를 기술하고에 의해 수정 된 코드를 발견했습니다. 그것은 라인Sharepoint 2013 - 목록의 마지막 수정 날짜 가져 오기

<input id="btnGetFieldUserValue" onclick="getFieldUserValue()" type="button" value="Get Created by and Modified by"/> 

을했을 때 잘 작동하지만되었다 내가 셰어 2013

도움말의 콘텐츠 편집기는 WebPart에서

<div id="create" onload="getFieldUserValue()"> &#160;</div> 

에 더 휴식을 변경하지 않을 때.

내 작업은 목록의 마지막 업데이트 시간을 보여주는 것입니다. 다른 방법으로 공유하십시오.

var listItem; 
    var list; 
    var clientContext; 

    function getFieldUserValue() { 

     this.clientContext = SP.ClientContext.get_current(); 
     if (this.clientContext != undefined && clientContext != null) { 
      var webSite = clientContext.get_web(); 
      this.list = webSite.get_lists().getByTitle("Resource Readiness"); 
      this.listItem = list.getItemById(1); 
      clientContext.load(this.listItem); 
      this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed)); 
     } 
    } 

    function OnLoadSuccess(sender, args) { 
     var fieldUserValueCreatedBy = this.listItem.get_item("Author"); 
     var fieldUserValueModifiedBy = this.listItem.get_item("Editor"); 
     document.getElementById("create").innerHTML = fieldUserValueModifiedBy.get_lookupValue() ; 
     alert("Created By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n Modified By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n"); 
    } 


    function OnLoadFailed(sender, args) { 
     alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
    }</script> 
 

답변

0

당신은 스크립트 파일을 기다릴 필요가 :

 function getFieldUserValue(){ 
      SP.SOD.executeOrDelayUntilScriptLoaded(loadContext, 'sp.js'); 
    } 
    function loadContext() { 
      this.clientContext = SP.ClientContext.get_current(); 
     if (this.clientContext != undefined && clientContext != null) { 
      var webSite = clientContext.get_web(); 
      this.list = webSite.get_lists().getByTitle("Resource Readiness"); 
      this.listItem = list.getItemById(1); 
      clientContext.load(this.listItem); 
      this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed)); 
     } 
    } 

    function OnLoadSuccess(sender, args) { 
     var fieldUserValueCreatedBy = this.listItem.get_item("Author"); 
     var fieldUserValueModifiedBy = this.listItem.get_item("Editor"); 
     document.getElementById("create").innerHTML = fieldUserValueModifiedBy.get_lookupValue() ; 
     alert("Created By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n Modified By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n"); 
    } 


    function OnLoadFailed(sender, args) { 
     alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
    } 
+0

하지 작업 .. (모두 시도하지만) 난 콘텐츠 편집기 또는 스크립트 편집기에서이 코드를 사용해야합니다. 결과 없음 – abhi5800

+0

스크립트 편집기에 추가 : _spBodyOnLoadFunctionNames.push ("getFieldUserValue"); –

+0

감사합니다. !! 알았다.! – abhi5800