Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Summarize Node): Option to continue when field to summarize can't be found in any items #9118

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/nodes-base/nodes/Transform/Summarize/Summarize.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
fieldValueGetter,
splitData,
} from './utils';
import { generatePairedItemData } from '../../../utils/utilities';

export class Summarize implements INodeType {
description: INodeTypeDescription = {
Expand Down Expand Up @@ -239,6 +240,14 @@ export class Summarize implements INodeType {
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Continue if Field Not Found',
name: 'continueIfFieldNotFound',
type: 'boolean',
default: false,
description:
"Whether to continue if field to summarize can't be found in any items and return single empty item, owerwise an error would be thrown",
},
{
displayName: 'Disable Dot Notation',
name: 'disableDotNotation',
Expand Down Expand Up @@ -304,7 +313,17 @@ export class Summarize implements INodeType {
const nodeVersion = this.getNode().typeVersion;

if (nodeVersion < 2.1) {
checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue);
try {
checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue);
} catch (error) {
if (options.continueIfFieldNotFound) {
const itemData = generatePairedItemData(items.length);

return [[{ json: {}, pairedItem: itemData }]];
} else {
throw error;
}
}
}

const aggregationResult = splitData(
Expand Down
1 change: 1 addition & 0 deletions packages/nodes-base/nodes/Transform/Summarize/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const AggregationDisplayNames = {
export const NUMERICAL_AGGREGATIONS = ['average', 'sum'];

export type SummarizeOptions = {
continueIfFieldNotFound: boolean;
disableDotNotation?: boolean;
outputFormat?: 'separateItems' | 'singleItem';
skipEmptySplitFields?: boolean;
Expand Down
Loading