Skip to content

Commit

Permalink
Allow case-insensitive column name Id on spo listitem batch remove. C…
Browse files Browse the repository at this point in the history
…loses #6419
  • Loading branch information
Saurabh7019 committed Oct 12, 2024
1 parent 7be7794 commit a4d712c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/m365/spo/commands/listitem/listitem-batch-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ class SpoListItemBatchRemoveCommand extends SpoCommand {
const fileContent = fs.readFileSync(args.options.filePath, 'utf-8');
const jsonContent: any[] = formatting.parseCsvToJson(fileContent);

if (!jsonContent[0].hasOwnProperty('ID')) {
const idRow = Object.keys(jsonContent[0]).find(key => key.toLowerCase() === 'id');

if (!idRow) {
return `The file does not contain the required header row with the column name 'ID'.`;
}

const nonNumbers = jsonContent.filter(element => isNaN(Number(element['ID'].toString().trim()))).map(element => element['ID']);
const nonNumbers = jsonContent.filter(element => isNaN(Number(element[idRow].toString().trim()))).map(element => element[idRow]);

if (nonNumbers.length > 0) {
return `The specified ids '${nonNumbers.join(', ')}' are invalid numbers.`;
Expand Down Expand Up @@ -167,7 +169,10 @@ class SpoListItemBatchRemoveCommand extends SpoCommand {
if (args.options.filePath) {
const csvContent = fs.readFileSync(args.options.filePath, 'utf-8');
const jsonContent = formatting.parseCsvToJson(csvContent);
idsToRemove = jsonContent.map((item: { ID: string }) => item['ID']);

const idRow = Object.keys(jsonContent[0]).find(key => key.toLowerCase() === 'id');

idsToRemove = idRow && jsonContent.map((item: any) => item[idRow]);
}
else {
idsToRemove = formatting.splitAndTrim(args.options.ids!);
Expand Down

0 comments on commit a4d712c

Please sign in to comment.