Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 4f46949

Browse files
Merge pull request #587 from patrick-rodgers/dev
adding item type name as param in item.update as per #580
2 parents 8be8965 + 00bd3dd commit 4f46949

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/sharepoint/items.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,16 @@ export class Item extends SharePointQueryableShareableItem {
181181
* @param properties A plain object hash of values to update for the list
182182
* @param eTag Value used in the IF-Match header, by default "*"
183183
*/
184-
public update(properties: TypedHash<any>, eTag = "*"): Promise<ItemUpdateResult> {
184+
public update(properties: TypedHash<any>, eTag = "*", listItemEntityTypeFullName: string = null): Promise<ItemUpdateResult> {
185185

186186
return new Promise<ItemUpdateResult>((resolve, reject) => {
187187

188188
const removeDependency = this.addBatchDependency();
189189

190-
const parentList = this.getParent(SharePointQueryableInstance, this.parentUrl.substr(0, this.parentUrl.lastIndexOf("/")));
191-
192-
parentList.select("ListItemEntityTypeFullName").getAs<{ ListItemEntityTypeFullName: string }>().then((d) => {
190+
return this.ensureListItemEntityTypeName(listItemEntityTypeFullName).then(listItemEntityType => {
193191

194192
const postBody = JSON.stringify(Util.extend({
195-
"__metadata": { "type": d.ListItemEntityTypeFullName },
193+
"__metadata": { "type": listItemEntityType },
196194
}, properties));
197195

198196
removeDependency();
@@ -265,6 +263,18 @@ export class Item extends SharePointQueryableShareableItem {
265263
body: JSON.stringify({ "formValues": formValues, bNewDocumentUpdate: newDocumentUpdate }),
266264
});
267265
}
266+
267+
/**
268+
* Ensures we have the proper list item entity type name, either from the value provided or from the list
269+
*
270+
* @param candidatelistItemEntityTypeFullName The potential type name
271+
*/
272+
private ensureListItemEntityTypeName(candidatelistItemEntityTypeFullName: string): Promise<string> {
273+
274+
return candidatelistItemEntityTypeFullName ?
275+
Promise.resolve(candidatelistItemEntityTypeFullName) :
276+
this.getParent(List, this.parentUrl.substr(0, this.parentUrl.lastIndexOf("/"))).getListItemEntityTypeFullName();
277+
}
268278
}
269279

270280
export interface ItemAddResult {

0 commit comments

Comments
 (0)