@@ -237,9 +237,8 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
237
237
}
238
238
239
239
}
240
+ // Otherwise, depending on the content type ID of the item, if any, we need to behave accordingly
240
241
else {
241
-
242
- // Otherwise, depending on the content type ID of the item, if any, we need to behave accordingly
243
242
if ( contentTypeId === undefined || contentTypeId === '' || ! contentTypeId . startsWith ( '0x0120' ) ) {
244
243
// We are adding a new list item
245
244
try {
@@ -257,18 +256,30 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
257
256
} else if ( contentTypeId !== undefined && contentTypeId !== '' && contentTypeId . startsWith ( '0x0120' ) ) {
258
257
// We are adding a folder or a Document Set
259
258
try {
259
+ const idField = 'ID' ;
260
+ const titleField = 'Title' ;
261
+ const contentTypeIdField = 'ContentTypeId' ;
262
+
260
263
const library = await sp . web . lists . getById ( listId ) ;
261
- const newFolder = await library . rootFolder . addSubFolderUsingPath ( objects [ 'Title' ] ) ;
264
+ const folderTitle = ( objects [ titleField ] !== undefined && objects [ titleField ] !== '' ) ?
265
+ encodeURIComponent ( objects [ titleField ] ) : '' ; // Empty string will be replaced by SPO with Folder Item ID
266
+ const newFolder = await library . rootFolder . addSubFolderUsingPath ( folderTitle ) ;
262
267
const fields = await newFolder . listItemAllFields ( ) ;
263
- const folderId = fields [ 'ID' ] ;
268
+ if ( fields [ idField ] !== undefined ) {
264
269
265
- // Set the content type ID for the target item
266
- objects [ 'ContentTypeId' ] = contentTypeId ;
270
+ // Read the ID of the just created folder or Document Set
271
+ const folderId = fields [ idField ] ;
267
272
268
- // Update the just created folder or Document Set
269
- const iur = await library . items . getById ( folderId ) . update ( objects ) ;
270
- if ( onSubmitted ) {
271
- onSubmitted ( iur . data , this . props . returnListItemInstanceOnSubmit !== false ? iur . item : undefined ) ;
273
+ // Set the content type ID for the target item
274
+ objects [ contentTypeIdField ] = contentTypeId ;
275
+
276
+ // Update the just created folder or Document Set
277
+ const iur = await library . items . getById ( folderId ) . update ( objects ) ;
278
+ if ( onSubmitted ) {
279
+ onSubmitted ( iur . data , this . props . returnListItemInstanceOnSubmit !== false ? iur . item : undefined ) ;
280
+ }
281
+ } else {
282
+ throw new Error ( 'Unable to read the ID of the just created folder or Document Set' ) ;
272
283
}
273
284
}
274
285
catch ( error ) {
0 commit comments