在作为BCS字段的Lookup中设置一个值 [英] Set a value in a Lookup that is a BCS field

查看:60
本文介绍了在作为BCS字段的Lookup中设置一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我在SharePoint Online中有一张桌子.在该表中,我有一个字段,它是对外部表的查找.现在,我必须从c#中的Azure函数中设置一个值,以便使用客户端对象模型.

Hi! I have a table in SharePoint Online. In that table I have a field that is a Lookup to an external table. Now I have to set a value from an Azure Function in c# so I'm using the client side object model.

我已经阅读了很多关于此的博客文章,但是我发现的所有文章都使用服务器端代码,由于示例适用于SP 2010,并且使用的类是否为描述性类,因此我无法将其转换为CSOM代码实现了i CSOM库.

I have read a lot of blog posts about this but all the posts that I have found is using server-side code and I cannot translate that into CSOM code because the examples are for SP 2010 and using classes that are depricated or not implemented i CSOM libraries.

我不知道该怎么做才能将价值带入领域,所以我需要索姆帮助.

I dont know what to do to get values into the field so I need som help please.

推荐答案

对于查找字段,如果要使用CSOM设置值,我们可以为该字段设置查找ID,这是一个代码段供您参考:

For a lookup field, if want to set value using CSOM, we can set the lookup Id for the field, here is a code snippet for your reference:

            string siteCollectionUrl = "https://xxxx.sharepoint.com/sites/xxx";
            string userName = "xxx@xxx.onmicrosoft.com";
            string password = "xxx";

            // Namespace: Microsoft.SharePoint.Client  
            ClientContext ctx = new ClientContext(siteCollectionUrl);

            // Namespace: System.Security
            SecureString secureString = new SecureString();
            password.ToList().ForEach(secureString.AppendChar);

            // Namespace: Microsoft.SharePoint.Client  
            ctx.Credentials = new SharePointOnlineCredentials(userName, secureString);

            // Namespace: Microsoft.SharePoint.Client  
            Site site = ctx.Site;

            ctx.Load(site);
            ctx.ExecuteQuery();
            var allproperties = ctx.Web.AllProperties;
            ctx.Load(allproperties);
            ctx.ExecuteQuery();
            List list = ctx.Web.Lists.GetByTitle("xxx");
            ctx.Load(list);
            ctx.ExecuteQuery();
            CamlQuery query = new CamlQuery();
            ListItemCollection items = list.GetItems(query);
            ctx.Load(items);
            ctx.ExecuteQuery();
            ListItem item = items[0];
            FieldLookupValue lv = item["testlookup"] as FieldLookupValue;
            if (lv!=null)
            {
                lv.LookupId = 1;
                item["testlookup"] = lv;
                item.Update();
                ctx.ExecuteQuery();
            }

使用您的网站URL,用户凭证,列表名称和字段名称进行更改,使其起作用,设置查找字段值,这全部基于查找ID,查找数据源来自外部列表,请检查外部列表中的ID并 可以.

Change the site url, user credential, list name and field name with yours to make it work, to set the lookup field value, it is all based on the lookup id, the lookup datasource comes from an external list, please check the ID in the external list and make it work.

谢谢

最好的问候


这篇关于在作为BCS字段的Lookup中设置一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆