我正在通过XML创建一个字段并尝试为其命名:
.then((lookupList): Promise<any> => {
console.log("getJobsForLocation | lookupList.Id: ", lookupList.Id);
let batchCreate = sp.web.createBatch();
let fieldXml = `<Field Name="FieldName" Type="Lookup" DisplayName="DisplayName" List="{${lookupList.Id}}" ShowField="Title"/>`;
ler.list.fields.createFieldAsXml(fieldXml);
return batchCreate.execute();
})
我的问题是,名称始终为“ DisplayName”
字段名称不是“ FieldName”吗?我希望字段名称和显示名称不同。
答案 0 :(得分:0)
您必须使用StaticName属性:
let fieldXml = `<Field Name="FieldName" StaticName="FieldName" Type="Lookup" DisplayName="DisplayName" List="{${lookupList.Id}}" ShowField="Title"/>`;
答案 1 :(得分:0)
发布在@ pnp / sp的github上;这是一个已知问题,但无法解决。
这是REST API行为细微差别,恐怕我们无法在库中对此进行修改。
建议在创建字段后更新名称:
ler.list.fields.inBatch(batchCreate).createFieldAsXml(`<Field Name="${kRegion} DisplayName="${kRegion}" Type="Lookup" List="{${values[1]}}" ShowField="Title" Required="TRUE"/>`);
batchCreate.execute()
.then(() => {
ler.list.fields.getByTitle(kRegion).inBatch(batchUpdate).update({
Title: removeCamelCase(kRegion)
});
});