@@ -8,6 +8,7 @@ import { Util } from "../utils/util";
88import * as Types from "./types" ;
99import { ODataParserBase } from "./odata" ;
1010import { AttachmentFiles } from "./attachmentfiles" ;
11+ import { List } from "./lists" ;
1112
1213/**
1314 * Describes a collection of Item objects
@@ -58,29 +59,42 @@ export class Items extends QueryableCollection {
5859 *
5960 * @param properties The new items's properties
6061 */
61- public add ( properties : TypedHash < any > = { } ) : Promise < ItemAddResult > {
62+ public add ( properties : TypedHash < any > = { } , listItemEntityTypeFullName : string = null ) : Promise < ItemAddResult > {
6263
63- let removeDependency = this . addBatchDependency ( ) ;
64-
65- let parentList = this . getParent ( QueryableInstance ) ;
66-
67- return parentList . select ( "ListItemEntityTypeFullName" ) . getAs < { ListItemEntityTypeFullName : string } > ( ) . then ( ( d ) => {
64+ let doAdd = ( listItemEntityType : string ) : Promise < ItemAddResult > => {
6865
6966 let postBody = JSON . stringify ( Util . extend ( {
70- "__metadata" : { "type" : d . ListItemEntityTypeFullName } ,
67+ "__metadata" : { "type" : listItemEntityType } ,
7168 } , properties ) ) ;
7269
73- let promise = this . postAs < { Id : number } > ( { body : postBody } ) . then ( ( data ) => {
70+ return this . postAs < { Id : number } > ( { body : postBody } ) . then ( ( data ) => {
7471 return {
7572 data : data ,
7673 item : this . getById ( data . Id ) ,
7774 } ;
7875 } ) ;
7976
80- removeDependency ( ) ;
77+ }
8178
82- return promise ;
83- } ) ;
79+ if ( ! listItemEntityTypeFullName ) {
80+
81+ let parentList = this . getParent ( List ) ;
82+
83+ let removeDependency = this . addBatchDependency ( ) ;
84+
85+ return parentList . getListItemEntityTypeFullName ( ) . then ( n => {
86+
87+ let promise = doAdd ( n ) ;
88+
89+ removeDependency ( ) ;
90+
91+ return promise ;
92+ } ) ;
93+
94+ } else {
95+
96+ return doAdd ( listItemEntityTypeFullName ) ;
97+ }
8498 }
8599}
86100
0 commit comments