zoukankan      html  css  js  c++  java
  • [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 );
  • 相关阅读:
    Log4j2 配置
    Spring + SpringMVC配置
    Tomcat 动态数据库连接池
    MySQL数据库备份命令
    一条insert语句插入数据库
    tomcat 性能优化
    linux RPM manager
    mysql 多主
    ceph学习
    python常用程序算法
  • 原文地址:https://www.cnblogs.com/cwyang/p/5643561.html
Copyright © 2011-2022 走看看