Sharepoint 2013 - 获取列表的上次修改日期

时间:2014-09-17 15:37:08

标签: sharepoint sharepoint-2013 sharepoint-list

尝试获取Sharepoint列表的上次修改时间。找到一个陈述作者并修改的代码。当它有行

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

但是当我改为

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

在sharepoint 2013的内容编辑器webpart中没有休息。

帮助。

我的任务是显示列表的上次更新时间。任何其他方式,请分享。   

    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> 
 

1 个答案:

答案 0 :(得分: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());
    }