SharePoint 2013快速编辑视图 - 如何在选择列时自动填充某些列数据 [英] SharePoint 2013 Quick Edit View-How to Auto fill some columns data in the selection of a column
问题描述
假设我在自定义列表中有3列Email,Name,EmployeeId,我在Qucik Edit视图中打开它,只输入2-3行电子邮件并想填写Name和EmployeeId(其他数据将从用户配置文件中查询),有什么方法可以做到这一点吗?
Vishal Goyal
我们需要使用脚本来实现这一点。
从此列表中检索所有项目,并使用API"/ _api基于每个电子邮件值从站点查找用户配置文件/ Web / SiteUsers
filter = Email eq< value>"。
这是一个代码示例。使用下面的脚本,单击"更新"以填充字段,然后单击"刷新"按钮刷新页面。
< script src = QUOT; HTTPS://code.jquery.com/jquery-1.10.2.min.js"类型= QUOT;文本/ JavaScript的">< /脚本>
< script type =" text / javascript">
var clientContext;
函数Update(){
SP.SOD.executeFunc('sp.js','SP.ClientContext',function(){
var listName =" email";
clientContext = new SP.ClientContext();
var oList = clientContext.get_web()。get_lists()。getByTitle(listName );
var camlQuery = new SP.CamlQuery();
//返回所有项目
this.collListItem = oList.getItems(camlQuery) );
clientContext.load(collListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this,this.updateItems),
Function.crea teDelegate(this,this.onQueryFailed)
);
});
}
函数updateItems(sender,args){
var listItemEnumerator = collListItem.getEnumerator();
//迭代项
while(listItemEnumerator.moveNext()){
var oListItem = listItemEnumerator.get_current();
// get item email
var email = oListItem.get_item(" Email");
if(email!== null){
var user = getUserProperties(email);
if(user!== null){
var name = user.LoginName;
var userId = user.Id;
//更新字段
oListItem.set_item(" Name",name);
oListItem.set_item(" EmployeeId",userId);
oListItem.update();
clientContext.executeQueryAsync(
Function.createDelegate(this,this.onQuerySucceeded),
Function.createDelegate(this,this.onQueryFailed)
);
}
}
}
}
函数getUserProperties(email){
var result;
//基于电子邮件获取网站用户
var requestUri = _spPageContextInfo.webAbsoluteUrl +" / _ api / Web / SiteUsers?
< blockquote> filter = Email eq'" + email +"'" ;;
Suppose I have 3 columns Email,Name, EmployeeId in a Custom List, I open this in Qucik Edit view ,ennterd Email Only for 2-3 rows and want to fill Name and EmployeeId (rest of data will be queried from User Profile), Is there any way I can do this?
Vishal Goyal
Hi,
We need use script to achieve that.
Retrieve all items from this list and find user profiles from the site based on the each email value using API "/_api/Web/SiteUsers
filter=Email eq <value>".Here is a code example. Using the script below, click the "Update" to populate the fields and then click "Refresh" button to refresh the page.
<script src="https://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script> <script type="text/javascript"> var clientContext; function Update() { SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { var listName = "email"; clientContext = new SP.ClientContext(); var oList = clientContext.get_web().get_lists().getByTitle(listName); var camlQuery = new SP.CamlQuery(); // Returns all items this.collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync( Function.createDelegate(this, this.updateItems), Function.createDelegate(this, this.onQueryFailed) ); }); } function updateItems(sender, args) { var listItemEnumerator = collListItem.getEnumerator(); // iterate items while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); // get item email var email = oListItem.get_item("Email"); if (email !== null){ var user = getUserProperties(email); if(user !== null){ var name = user.LoginName; var userId = user.Id; //update fields oListItem.set_item("Name", name); oListItem.set_item("EmployeeId", userId); oListItem.update(); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); } } } } function getUserProperties(email){ var result; // get the site user based on email var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/SiteUsers?
filter=Email eq '"+email+"'";
这篇关于SharePoint 2013快速编辑视图 - 如何在选择列时自动填充某些列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!