如何插入SharePoint列表从另一个列表(SharePoint Apps)中查找列?

时间:2014-01-03 08:24:10

标签: sharepoint-2013

如何将查找列值插入SharePoint列表。我创建了一个sharepoint托管应用程序并创建了两个SharePoint list1和list2。我在list2上创建新记录并将list1中的一些数据加载到下拉框中,并尝试将list1中的id和title值插入list2(查找值)。请给我一些建议或源代码示例。谢谢&问候,托拉。

1 个答案:

答案 0 :(得分:0)

如何在SharePoint 2010/2013中使用JavaScript(CSOM)配置字段

1 提供清单列

function ProvisionFieldInList(fieldSchema, listTitle)
      {
            var context = SP.ClientContext.get_current();
            var list = context.get_web().get_lists().getByTitle(listTitle);
            var fields = list.get_fields();
            var fieldToAdd = fields.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.AddToDefaultContentType);
            fieldToAdd.update();
            context.load(list);
            context.load(fields);
            context.load(fieldToAdd);
            context.executeQueryAsync(
                  function(){
                     //Provisioned successfully                
                  }, 
                  function(sender, args){
                     //Error handling goes here...
                  });
      }

2 提供网站专栏

function ProvisionField(fieldSchema)
  {
        var context = SP.ClientContext.get_current();
        var fields = context.get_web().get_fields();
        var fieldToAdd = fields.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.AddToDefaultContentType);
        fieldToAdd.update();
        context.load(fields);
        context.load(fieldToAdd);
        context.executeQueryAsync(
              function(sender, args){
                 //Provisioned successfully                
              }, 
              function(sender, args){
                 //Error handling goes here...
              });
  }

用法

以下示例演示了如何创建查找字段

function CreateLookupFields()
{

      var lookupFieldSchema = ["<Field Type='Lookup' DisplayName='OfficeType'",
                                    "Required='FALSE'",  
                                    "List='{E0D2646A-63BE-4010-ABC7-4A5E2B8EF0E7}'",
                                    "ShowField='Title'", 
                                    "StaticName='OfficeType'",
                                    "Name='OfficeType'/>"].join(' ');

      //Create Lookup field for List 
      ProvisionFieldInList(lookupFieldSchema,'Nokia Offices');


      var lookupFieldSchema2 = ["<Field Type='Lookup' DisplayName='OfficeType2'",
                                    "Required='FALSE'",  
                                    "List='{E0D2646A-63BE-4010-ABC7-4A5E2B8EF0E7}'",
                                    "ShowField='Title'", 
                                    "StaticName='OfficeType2'",
                                    "Name='OfficeType2'/>"].join(' ');

      //Create Lookup field in web
      ProvisionField(lookupFieldSchema2);                              

}      

SP.SOD.executeOrDelayUntilScriptLoaded(CreateLookupField, 'sp.js');