Skip to content

Commit

Permalink
Merge pull request #162 from texei/Jb-P-org-skip-null-fields
Browse files Browse the repository at this point in the history
Jb p org skip null fields
  • Loading branch information
FabienTaillon authored Apr 30, 2024
2 parents d683452 + 59e0fe4 commit 75cb5b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion messages/data.export.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ path to data plan file

API Type to use

# flags.excludenullfields.summary
# flags.exclude-null-fields.summary

Exclude null fields from exported JSON files
17 changes: 8 additions & 9 deletions src/commands/texei/data/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ export default class Export extends SfCommand<ExportResult> {
options: ['rest', 'bulk'],
default: 'rest',
}),
// new flag to exclude null fields
excludenullfields: Flags.boolean({
'exclude-null-fields': Flags.boolean({
char: 'e',
summary: messages.getMessage('flags.excludenullfields.summary'),
summary: messages.getMessage('flags.exclude-null-fields.summary'),
default: false,
}),
// loglevel is a no-op, but this flag is added to avoid breaking scripts and warn users who are using it
Expand Down Expand Up @@ -312,7 +311,11 @@ export default class Export extends SfCommand<ExportResult> {
const recordFile: any = {};
recordFile.attributes = objectAttributes;

recordFile.records = recordResults.map((record) => removeNullFields(record, flags.excludenullfields));
if (flags['exclude-null-fields'] === true) {
recordFile.records = recordResults.map((record) => removeNullFields(record));
} else {
recordFile.records = recordResults;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return recordFile;
Expand Down Expand Up @@ -428,11 +431,7 @@ export default class Export extends SfCommand<ExportResult> {
}

// add function to remove null values from object
function removeNullFields(record: { [key: string]: any }, excludeNullFields: boolean): { [key: string]: any } {
if (!excludeNullFields) {
return record;
}

function removeNullFields(record: { [key: string]: any }): { [key: string]: any } {
const filteredRecord: { [key: string]: any } = {};
for (const key in record) {
if (record[key] !== null) {
Expand Down

0 comments on commit 75cb5b0

Please sign in to comment.