根据其他文档库项目计数更新当前列表项目值 [英] update current list item value based on other document library items count

查看:65
本文介绍了根据其他文档库项目计数更新当前列表项目值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新我的自定义列表列数据之一(选择下拉菜单-完成1)2)待处理)基于与此列表相关的文档库项目,并且在文档库中有一个查找列. /p>

条件是,如果文档库由5个与自定义"列表相关的项目组成,则自定义列表"的状态列将更新为已完成,如果项目少于5个,则列状态将处于待处理状态.

我怎么能做到这一点.

谢谢


sal

解决方案

阿里,

一种选择是过滤库中不为null的查找字段并获取项目计数,然后使用JavaScript更新选择字段.

下面的一些代码演示会有所帮助:

<脚本类型="文本/javascript">
var oList
ExecuteOrDelayUntilScriptLoaded(GetItemCount,'sp.js');
函数GetItemCount(){
    clientContext =新的SP.ClientContext.get_current();
    web = clientContext.get_web();
    oList = web.get_lists().getByTitle("Documents");
    clientContext.load(oList);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml(< Where>< IsNotNull>< FieldRef Name ='lookup'/></IsNotNull></Where>));
this.collListItem = oList.getItems(camlQuery);
console.log(collListItem);
    clientContext.load(collListItem);
    clientContext.executeQueryAsync(onSuccess,onFail);
}
函数onSuccess(sender,args){
    alert('行数:'+ collListItem.get_count());
//console.log(oList.get_itemcount());
if(collListItem.get_count()== 5)
{
UpdateChoice();
}
}
函数onFail(sender,args){
    alert('请求失败.\ n'+ args.get_message()+'\ n'+ args.get_stackTrace());
}


函数UpdateChoice()
{
    clientContext =新的SP.ClientContext.get_current();
    web = clientContext.get_web();
    var oList = web.get_lists().getByTitle("DataList");
    clientContext.load(oList);
var listItem = oList.getItemById(1);
listItem.set_item('Status','pending');
    listItem.update();
    clientContext.load(listItem);
    clientContext.executeQueryAsync(onUpdateSuccess,onUpdateFail);
}

函数onUpdateSuccess(){
            alert('更新成功');
}
函数onUpdateFail(sender,args){
    alert('请求失败.'+ args.get_message()+'\ n'+ args.get_stackTrace());
}
</script>

您可以参考上面的代码,并根据自己的逻辑进行更改以实现它.

谢谢

最好的问候


hi,

I want to update one of my custom list column data (choice dropdown-- 1) completed 2) pending) based on documents library items which are related to this list and in document library there is lookup column.

the condition is if the document library consist of 5 items which are related to the Custom list then the status column of the custom list will be updated to completed, if the items are less then 5 the column status will be pending.

how can i achieve this.

Thanks


sal

解决方案

Hi Ali,

One option is that filter the lookup field in the library which is not null and get the count for the item count,then update the choice field using JavaScript.

Here are some code demos would be helpful:

<script type="text/javascript">
var oList
ExecuteOrDelayUntilScriptLoaded(GetItemCount,'sp.js');
function GetItemCount() {
    clientContext = new SP.ClientContext.get_current();
    web = clientContext.get_web();
    oList = web.get_lists().getByTitle("Documents");
    clientContext.load(oList);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("<Where><IsNotNull><FieldRef Name='lookup' /></IsNotNull></Where>");
	this.collListItem = oList.getItems(camlQuery);
	console.log(collListItem);
    clientContext.load(collListItem);
    clientContext.executeQueryAsync(onSuccess, onFail);
}
function onSuccess(sender, args) {
    alert('No of rows: ' + collListItem.get_count());
	//console.log(oList.get_itemcount());
	if(collListItem.get_count()==5)
	{
	  UpdateChoice();
	}
}
function onFail(sender, args) {
    alert('Request failed.\n' + args.get_message() + '\n' + args.get_stackTrace());
}


function UpdateChoice()
{
    clientContext = new SP.ClientContext.get_current();
    web = clientContext.get_web();
    var oList = web.get_lists().getByTitle("DataList");
    clientContext.load(oList);
	var listItem=oList.getItemById(1);
	listItem.set_item('Status', 'pending');
    listItem.update();
    clientContext.load(listItem);
    clientContext.executeQueryAsync(onUpdateSuccess, onUpdateFail);
}

function onUpdateSuccess() {
            alert('update success');
}
function onUpdateFail(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}   
</script>

You can refer the code above and change with your logic to achieve it.

Thanks

Best Regards


这篇关于根据其他文档库项目计数更新当前列表项目值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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