@kwiz/common 1.0.42 → 1.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/collections.base.js +1 -1
- package/dist/helpers/sharepoint.d.ts +1 -0
- package/dist/helpers/sharepoint.js +14 -1
- package/dist/helpers/sharepoint.js.map +1 -1
- package/dist/utils/sharepoint.rest/item.js +4 -4
- package/dist/utils/sharepoint.rest/item.js.map +1 -1
- package/dist/utils/sharepoint.rest/list.d.ts +4 -0
- package/dist/utils/sharepoint.rest/list.js +79 -42
- package/dist/utils/sharepoint.rest/list.js.map +1 -1
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +9 -7
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -1
- package/dist/utils/sharepoint.rest/web.js +4 -4
- package/dist/utils/sharepoint.rest/web.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/sharepoint.rest/list.ts +77 -39
|
@@ -401,10 +401,11 @@ export function UserHasPermissionsSync(siteUrlOrId: string, listIdOrTitle: strin
|
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
/** create a new column and try to add it to default view. Send either Title and Type, or SchemaXml. Create with SchemaXml also adds to all content types */
|
|
404
|
-
export function CreateField(siteUrl: string, listIdOrTitle: string, options: {
|
|
404
|
+
export async function CreateField(siteUrl: string, listIdOrTitle: string, options: {
|
|
405
405
|
Title?: string;
|
|
406
406
|
Type?: FieldTypes;
|
|
407
407
|
Required?: boolean;
|
|
408
|
+
Indexed?: boolean;
|
|
408
409
|
SchemaXml?: string;
|
|
409
410
|
SchemaXmlSpecificInternalName?: boolean;
|
|
410
411
|
SkipAddToDefaultView?: boolean;
|
|
@@ -415,32 +416,33 @@ export function CreateField(siteUrl: string, listIdOrTitle: string, options: {
|
|
|
415
416
|
}): Promise<IFieldInfoEX> {
|
|
416
417
|
siteUrl = GetSiteUrl(siteUrl);
|
|
417
418
|
|
|
418
|
-
let finish = async (result:
|
|
419
|
-
if (result
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
|
|
419
|
+
let finish = async (result: IFieldInfo) => {
|
|
420
|
+
if (!result) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
423
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
GetListViews(siteUrl, listIdOrTitle).then(views => {
|
|
428
|
-
let defaultView = firstOrNull(views, v => v.DefaultView);
|
|
429
|
-
if (defaultView)
|
|
430
|
-
GetJson(GetListRestUrl(siteUrl, listIdOrTitle) + `/views('${defaultView.Id}')/ViewFields/addViewField('${internalName}')`, null, { method: "POST", spWebUrl: siteUrl });
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
catch (e) { }
|
|
424
|
+
let internalName = result.InternalName;
|
|
425
|
+
//we need to clear and reload the list fields cache, so call it and return our field from that collection.
|
|
426
|
+
let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
|
|
435
427
|
|
|
436
|
-
|
|
428
|
+
try {
|
|
429
|
+
if (options.SkipAddToDefaultView !== true) {
|
|
430
|
+
//try to add it to default view, don't wait for it
|
|
431
|
+
GetListViews(siteUrl, listIdOrTitle).then(views => {
|
|
432
|
+
let defaultView = firstOrNull(views, v => v.DefaultView);
|
|
433
|
+
if (defaultView)
|
|
434
|
+
GetJson(GetListRestUrl(siteUrl, listIdOrTitle) + `/views('${defaultView.Id}')/ViewFields/addViewField('${internalName}')`, null, { method: "POST", spWebUrl: siteUrl });
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
437
|
}
|
|
438
|
-
|
|
438
|
+
catch (e) { }
|
|
439
|
+
|
|
440
|
+
return firstOrNull(fields, f => f.InternalName === internalName);
|
|
439
441
|
};
|
|
440
442
|
|
|
441
443
|
if (!isNullOrEmptyString(options.SchemaXml)) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
+
try {
|
|
445
|
+
let updateObject: IDictionary<any> = {
|
|
444
446
|
'parameters': {
|
|
445
447
|
'__metadata': { 'type': 'SP.XmlSchemaFieldCreationInformation' },
|
|
446
448
|
'SchemaXml': options.SchemaXml,
|
|
@@ -448,32 +450,51 @@ export function CreateField(siteUrl: string, listIdOrTitle: string, options: {
|
|
|
448
450
|
4 ://SP.AddFieldOptions.addToAllContentTypes
|
|
449
451
|
4 | 8//SP.AddFieldOptions.addToAllContentTypes | addFieldInternalNameHint
|
|
450
452
|
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
453
|
+
};
|
|
454
|
+
let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/fields/createFieldAsXml`;
|
|
455
|
+
let newFieldResult = await GetJson<{ d: IFieldInfo; }>(url, JSON.stringify(updateObject));
|
|
456
|
+
|
|
457
|
+
if (!isNullOrUndefined(newFieldResult)
|
|
458
|
+
&& !isNullOrUndefined(newFieldResult.d)) {
|
|
459
|
+
if ((!isNullOrEmptyString(options.Title) && options.Title !== newFieldResult.d.Title)
|
|
460
|
+
|| (isBoolean(options.Indexed) && options.Indexed !== newFieldResult.d.Indexed)) {
|
|
461
|
+
let updatedField = await UpdateField(siteUrl, listIdOrTitle, newFieldResult.d.InternalName, {
|
|
462
|
+
Title: options.Title,
|
|
463
|
+
Indexed: options.Indexed === true
|
|
464
|
+
});
|
|
465
|
+
return finish(updatedField);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return finish(newFieldResult && newFieldResult.d);
|
|
470
|
+
} catch {
|
|
471
|
+
}
|
|
472
|
+
return null;
|
|
473
|
+
} else if (!isNullOrEmptyString(options.Title) && !isNullOrUndefined(options.Type)) {
|
|
458
474
|
let updateObject: IDictionary<any> = {
|
|
459
475
|
'__metadata': { 'type': 'SP.Field' },
|
|
460
476
|
'Title': options.Title,
|
|
461
477
|
'FieldTypeKind': options.Type,
|
|
462
|
-
'Required': options.Required === true
|
|
478
|
+
'Required': options.Required === true,
|
|
479
|
+
'Indexed': options.Indexed === true
|
|
463
480
|
};
|
|
464
|
-
if (!isNullOrEmptyString(options.ClientSideComponentId))
|
|
481
|
+
if (!isNullOrEmptyString(options.ClientSideComponentId)) {
|
|
465
482
|
updateObject.ClientSideComponentId = options.ClientSideComponentId;
|
|
466
|
-
|
|
483
|
+
}
|
|
484
|
+
if (!isNullOrEmptyString(options.ClientSideComponentProperties)) {
|
|
467
485
|
updateObject.ClientSideComponentProperties = options.ClientSideComponentProperties;
|
|
468
|
-
|
|
486
|
+
}
|
|
487
|
+
if (!isNullOrEmptyString(options.JSLink)) {
|
|
469
488
|
updateObject.JSLink = options.JSLink;
|
|
489
|
+
}
|
|
470
490
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
491
|
+
try {
|
|
492
|
+
let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/fields`;
|
|
493
|
+
let newFieldResult = await GetJson<{ d: IFieldInfo; }>(url, JSON.stringify(updateObject));
|
|
494
|
+
return finish(newFieldResult && newFieldResult.d);
|
|
495
|
+
} catch {
|
|
496
|
+
}
|
|
497
|
+
return null;
|
|
477
498
|
}
|
|
478
499
|
else {
|
|
479
500
|
console.error("You must send either SchemaXml or Title and Type");
|
|
@@ -483,6 +504,9 @@ export function CreateField(siteUrl: string, listIdOrTitle: string, options: {
|
|
|
483
504
|
/** Update field SchemaXml OR Title, only 1 update at a time supported. */
|
|
484
505
|
export async function UpdateField(siteUrlOrId: string, listIdOrTitle: string, fieldInternalName: string, options: {
|
|
485
506
|
Title?: string;
|
|
507
|
+
Indexed?: boolean;
|
|
508
|
+
/** Update 'Choices' propertry on 'Choice' and 'MultiChoice' field types. */
|
|
509
|
+
Choices?: string[];
|
|
486
510
|
SchemaXml?: string;
|
|
487
511
|
FieldType?: FieldTypeAsString;
|
|
488
512
|
Required?: boolean;
|
|
@@ -499,6 +523,9 @@ export async function UpdateField(siteUrlOrId: string, listIdOrTitle: string, fi
|
|
|
499
523
|
return firstOrNull(fields, f => f.InternalName === fieldInternalName);
|
|
500
524
|
};
|
|
501
525
|
|
|
526
|
+
let fields = await GetListFieldsAsHash(siteUrl, listIdOrTitle, true);
|
|
527
|
+
let thisField = fields[fieldInternalName];
|
|
528
|
+
|
|
502
529
|
//updates can either be SchemaXml, or others. Cannot be both.
|
|
503
530
|
let updates: IDictionary<any> = {
|
|
504
531
|
'__metadata': { 'type': 'SP.Field' }
|
|
@@ -509,7 +536,6 @@ export async function UpdateField(siteUrlOrId: string, listIdOrTitle: string, fi
|
|
|
509
536
|
}
|
|
510
537
|
else {
|
|
511
538
|
//cannot send schema updates with other updates.
|
|
512
|
-
|
|
513
539
|
if (!isNullOrEmptyString(options.Title)) {
|
|
514
540
|
updates.Title = options.Title;
|
|
515
541
|
}
|
|
@@ -519,6 +545,18 @@ export async function UpdateField(siteUrlOrId: string, listIdOrTitle: string, fi
|
|
|
519
545
|
if (isBoolean(options.Required)) {
|
|
520
546
|
updates.Required = options.Required === true;
|
|
521
547
|
}
|
|
548
|
+
if (isBoolean(options.Indexed)) {
|
|
549
|
+
updates.Indexed = options.Indexed === true;
|
|
550
|
+
}
|
|
551
|
+
if (!isNullOrEmptyArray(options.Choices)) {
|
|
552
|
+
let choiceType = options.FieldType || thisField.TypeAsString;
|
|
553
|
+
if (choiceType === "Choice" || choiceType === "MultiChoice") {
|
|
554
|
+
updates["__metadata"]["type"] = choiceType === "Choice" ? "SP.FieldChoice" : "SP.FieldMultiChoice"
|
|
555
|
+
updates.Choices = { "results": options.Choices };
|
|
556
|
+
} else {
|
|
557
|
+
logger.warn("Can only update 'Choices' property on 'Choice' and 'MultiChoice' field types.");
|
|
558
|
+
}
|
|
559
|
+
}
|
|
522
560
|
if (isBoolean(options.Hidden)) {
|
|
523
561
|
//this requries the CanToggleHidden to be in the schema... if not - we will need to add it before we can update this.
|
|
524
562
|
let fields = await GetListFieldsAsHash(siteUrl, listIdOrTitle, false);
|