【问题标题】:how to get approval status field value in sharepoint client object model如何在共享点客户端对象模型中获取批准状态字段值
【发布时间】:2012-03-21 19:01:36
【问题描述】:

如何在 sharepoint 中使用客户端对象模型获取列表项批准状态值?

这是我获取其他属性值的示例代码。

ClientContext.Load(listItems,
                    items => items.Include(
                    item => item.Id,
                    item => item.DisplayName,
                    item => item.FileSystemObjectType,
                    item => item.HasUniqueRoleAssignments));

【问题讨论】:

    标签: sharepoint sharepoint-2010 sharepoint-2007 sharepoint-clientobject


    【解决方案1】:

    这是获取和设置(可选)批准状态的完整代码(this.oListItem.get_item('_ModerationStatus') 的可能值:0 - “已批准”,1 - “拒绝”,2-“待定”) :

    <script type="text/javascript" src="/jquery-1.10.2.min.js"></script>
    <script src="/jquery.SPServices-2013.02a.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    
    
    $(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(loadConstants, "sp.js"); });    
    
    
    function loadConstants() {
    
        var userid= _spPageContextInfo.userId;
        var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
        var requestHeaders = { "accept" : "application/json;odata=verbose" };
        $.ajax({
          url : requestUri,
          contentType : "application/json;odata=verbose",
          headers : requestHeaders,
          success : onSuccess,
          error : onError
        });
    
        function onSuccess(data, request){
            var loginName = data.d.Title;
    
            //get current (selected) list item id
            var docurl = document.URL;
            var beginindex = docurl.indexOf('?ID=') + 4;
            var endindex = docurl.indexOf('&Source=');
            var itemid = docurl.substring(beginindex, endindex);
    
            var ctx = new SP.ClientContext("your site url");
            var oList = ctx.get_web().get_lists().getByTitle('your list name');
            this.oListItem = oList.getItemById(itemid);         
    
            var appStatus = "";
            ctx.load(this.oListItem);
    
            ctx.executeQueryAsync(Function.createDelegate(this, function () {  
                                                        //get approval status
                                                        appStatus = this.oListItem.get_item('_ModerationStatus');                                                       
    
                                                        //set approval status to Approved (0)
                                                        this.oListItem.set_item('_ModerationStatus', 0);
                                                        this.oListItem.update();            
    
                ctx.executeQueryAsync(
                    Function.createDelegate(this, this.onQuerySucceeded), 
                    Function.createDelegate(this, this.onQueryFailed)
                );
    
            }),  function (sender, args) { alert('Error occured' + args.get_message());}); 
    
        }
        function onError(error) {
            alert("error");
        }       
    }
    
    </script>
    

    【讨论】:

    • 这是 java 脚本,但我使用的是 c#。不过这个问题早就解决了。希望其他人会发现它有帮助.. 谢谢
    【解决方案2】:

    您可以使用这样的方式获得批准状态

    ClientContext.Load(listItems,
                    items => items.Include(
                    item => item.Id,
                    item => item.DisplayName,
                    item => item["Status"]));
    

    您可以像这样获取任何字段自定义或 Sharepoint 默认字段值。

    【讨论】:

    • 我知道这个。但它不适用于状态。不知道为什么。建议另一个技巧。我认为 CAML 查询必须获取它(但它可以增加有效负载大小)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多