//人员空间的ID不可以有下划线。
//人员选项提交的时候需要将提交的字段加“Id”,这个是表中默认带的字段;
person类型是个复合类型。
<SharePoint:ClientPeoplePicker Title="peoplePicker" ID="Auditor" runat="server"
AllowMultipleEntities="True" OnUserResolvedClientScript="af.GetUsers"
ClientIDMode="Static" />
af.Auditeedepthead.userId;
数据表默认创建人和修改人字段名称:Author,Editor
提交多个人员:字段Id.results (ManagerId.results)
人员控件赋值,可修改方式:
$(function () {
ExecuteOrDelayUntilScriptLoaded(function () {
getItem(id);
}, "clientpeoplepicker.js");
})
$pnp.sp.web.lists.getByTitle("QualityAuditReport").items
.expand('Auditor,Coordinator').select('Title,AuditorId,Auditor/Title,Auditor/EMail,Auditor/Name,Coordinator/Name')
.filter("ID eq '" + id + "'")
.get().then(function (results) {
if (results.length > 0) {
var res = results[0];
if (res.Coordinator) {
var userField = $("#Coordinator_TopSpan_EditorInput").get(0);
var peoplepicker = SPClientPeoplePicker.PickerObjectFromSubElement(userField);
peoplepicker.AddUserKeys(res.Coordinator.Title);
}
}
})
//重名的时候他们email不会一样,然后用email反填
if (res.Auditeedepthead) {
var userField = $("#Auditeedepthead_TopSpan_EditorInput").get(0);
var peoplepicker = SPClientPeoplePicker.PickerObjectFromSubElement(userField);
//peoplepicker.AddUserKeys(res.Auditeedepthead.Title);
peoplepicker.AddUserKeys("i:0#.f|membership|" + res.Auditeedepthead.EMail);
}
注意:如果表中的字段类型需要改变,建议最好删掉,重新创建。
//下一个项目,尝试用workflow。
PnPjs 查询只能是List里的字段去匹配查询
Filter 查询条件:
• lt:less than 小于
• le:less than or equal to 小于等于
• eq:equal to 等于
• ne:not equal to 不等于
• ge:greater than or equal to 大于等于
• gt:greater than 大于
• $pnp.sp.web.lists.getByTitle("Config3").items.filter("substringof('"+name+"',Title)").get().then(function(d){}
• console.log(d);
• });
•
• $pnp.sp.web.lists.getByTitle("Config3").items.filter("startswith(Title,'"+name+"')").get().then(function(d){}
• console.log(d);
• });
•
// 新建的站点不能新建文件的解决方法:需要global运行命令
人员控件js:
var af= af||{};
(function($,af){
/**** people picker ***/
af.people={};
af.loginName={};
af.userName={};
af.email={};
af.initializePeoplePicker=function (peoplePickerElementId) {
// Create a schema to store picker properties, and set the properties.
var schema = {};
schema['PrincipalAccountType'] = 'User';
schema['SearchPrincipalSource'] = 15;
schema['ResolvePrincipalSource'] = 15;
schema['AllowMultipleValues'] = false;
schema['MaximumEntitySuggestions'] = 50;
//schema['Width'] = '280px';
schema['OnUserResolvedClientScript'] = 'af.GetUser';
SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
}
af.GetUser=function(topElementId, users){
var peoplePickerId=topElementId.split("_")[0];
//var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[topElementId];
if(users.length>0){
if(users[0].IsResolved){
var loginName=users[0].Key;
var userName=users[0].DisplayText;
af.userName[peoplePickerId]=userName;
af[peoplePickerId]={};
af[peoplePickerId].userName=userName;
af[peoplePickerId].loginName=loginName;
af[peoplePickerId].email=users[0].EntityData.Email;
af.GetUserId(peoplePickerId,loginName);
}
//add user to group
//var approverGroup=af.getGroupName("Approver");
//$pnp.sp.web.siteGroups.getByName(approverGroup).users.add(loginName);
}
}
af.GetUserId=function(peoplePickerId,loginName){
$pnp.sp.web.ensureUser(loginName).then(function (user)
{
var u = user;
af.loginName[peoplePickerId]=user.data.Id;
af[peoplePickerId].userId=user.data.Id;
});
}
//Users {"results": Array()}
af.GetUsers=function(topElementId, users){
var peoplePickerId=topElementId.split("_")[0];
//var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[topElementId];
var UsersId=[];
af[peoplePickerId]={};
af[peoplePickerId].users=[];
if(users.length>0){
for(i=0;i<users.length;i++)
{
if(users[i].IsResolved){
var loginName=users[i].Key;
var userName=users[i].DisplayText;
af.userName[peoplePickerId]=userName;
var obj={};
obj.userName=userName;
obj.loginName=loginName;
obj.email=users[i].EntityData.Email;
af[peoplePickerId].users.push(obj);
//af.GetUserId(peoplePickerId,loginName);
$pnp.sp.web.ensureUser(loginName).then(function (user)
{
var u = user;
UsersId.push(user.data.Id);
});
}
}
//af.loginName[peoplePickerId]=user.data.Id;
af[peoplePickerId].userId={"results": UsersId};
//af[peoplePickerId].userId=UsersId;
}
}
af.getGroupName=function(groupName){
var siteName=_spPageContextInfo.webTitle;
groupName=siteName+" "+groupName;
return groupName;
}
})(jQuery,af)
浙公网安备 33010602011771号