• [SharePoint]javascript client object model 获取lookup 类型的field的值,包括user类型(单人或者多人)的值。how to get the multiple user type/lookup type field value by Javascript client object model


    1. how to get value

     1 var context = new SP.ClientContext.get_current();
     2 var web = context.get_web();
     3 var list = web.get_lists().getByTitle(listTitle);
     4 var listItem = list.getItemById(1);   
     5 context.load(listItem);
     6 context.executeQueryAsync(
     7    function() {
     8        var lookupVals = listItem.get_item(fieldName); //get multi lookup value (SP.FieldLookupValue[])
     9        for(var i = 0;i < lookupVals.length;i++) {
    10            console.log(lookupVals[i].get_lookupId()); //print Id
    11            console.log(lookupVals[i].get_lookupValue()); //print Value
    12        }
    13    },
    14    function(sender,args){
    15        console.log(args.get_message());
    16    }
    17 );

    2. how to update value

     1 var context = new SP.ClientContext.get_current();
     2 var web = context.get_web();
     3 var list = web.get_lists().getByTitle(listTitle);
     4 var listItem = list.getItemById(1);   
     5 
     6 var lookupVals = [];
     7 //set 1st Lookup value
     8 var lookupVal1 = new SP.FieldLookupValue();
     9 lookupVal1.set_lookupId(1);
    10 lookupVals.push(lookupVal1);
    11 //set 2nd Lookup value
    12 var lookupVal2 = new SP.FieldLookupValue();
    13 lookupVal2.set_lookupId(2);
    14 lookupVals.push(lookupVal2);
    15 
    16 listItem.set_item(fieldName,lookupVals);
    17 listItem.update();
    18 
    19 context.executeQueryAsync(
    20    function() {
    21         console.log('Multi lookup field has been updated');
    22    },
    23    function(sender,args){
    24        console.log(args.get_message());
    25    }
    26 );
  • 相关阅读:
    Vue的watch监听事件
    Vue路由-命名视图实现经典布局
    Vue中使用children实现路由的嵌套
    Vue中router两种传参方式
    mysql 压缩备份 压缩还原 命令
    【转】SVN branches trunk 合并 讲解
    svn 更新提交文件冲突
    mysql 导出表数据表结构
    利用jenkins打造通过自定义参数更新svn 指定文件任务
    centos 7 安装jira 破解
  • 原文地址:https://www.cnblogs.com/cwyang/p/5643561.html
Copyright © 2020-2023  润新知