mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
feat(Summarize Node): Option to continue when field to summarize can't be found in any items (#9118)
This commit is contained in:
parent
cf435c3311
commit
d7abc30104
|
@ -14,6 +14,7 @@ import {
|
||||||
fieldValueGetter,
|
fieldValueGetter,
|
||||||
splitData,
|
splitData,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
import { generatePairedItemData } from '../../../utils/utilities';
|
||||||
|
|
||||||
export class Summarize implements INodeType {
|
export class Summarize implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -239,6 +240,14 @@ export class Summarize implements INodeType {
|
||||||
placeholder: 'Add Option',
|
placeholder: 'Add Option',
|
||||||
default: {},
|
default: {},
|
||||||
options: [
|
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',
|
displayName: 'Disable Dot Notation',
|
||||||
name: 'disableDotNotation',
|
name: 'disableDotNotation',
|
||||||
|
@ -304,7 +313,17 @@ export class Summarize implements INodeType {
|
||||||
const nodeVersion = this.getNode().typeVersion;
|
const nodeVersion = this.getNode().typeVersion;
|
||||||
|
|
||||||
if (nodeVersion < 2.1) {
|
if (nodeVersion < 2.1) {
|
||||||
|
try {
|
||||||
checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue);
|
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(
|
const aggregationResult = splitData(
|
||||||
|
|
|
@ -40,6 +40,7 @@ const AggregationDisplayNames = {
|
||||||
export const NUMERICAL_AGGREGATIONS = ['average', 'sum'];
|
export const NUMERICAL_AGGREGATIONS = ['average', 'sum'];
|
||||||
|
|
||||||
export type SummarizeOptions = {
|
export type SummarizeOptions = {
|
||||||
|
continueIfFieldNotFound: boolean;
|
||||||
disableDotNotation?: boolean;
|
disableDotNotation?: boolean;
|
||||||
outputFormat?: 'separateItems' | 'singleItem';
|
outputFormat?: 'separateItems' | 'singleItem';
|
||||||
skipEmptySplitFields?: boolean;
|
skipEmptySplitFields?: boolean;
|
||||||
|
|
Loading…
Reference in a new issue