Add and remove properties dynamically

For anyone with the same needs for dynamic inputs. You should use resourceMapper to list your inputs:


			{
				displayName: 'Inputs',
				name: 'inputs',
				type: 'resourceMapper',
				noDataExpression: true,
				default: {
					mappingMode: 'defineBelow',
					value: null,
				},
				required: true,
				typeOptions: {
					loadOptionsDependsOn: ['template'],
					resourceMapper: {
						resourceMapperMethod: 'getInputs',
						mode: 'update',
						fieldWords: {
							singular: 'input',
							plural: 'inputs',
						},
						addAllFields: true,
						multiKeyMatch: true,
					},
				},
			},

Inside Node class methods attributes you should define the getInputs as:


	methods = {
		resourceMapping: {
			getInputs
		},
	};

And getInputs should be using ResourceMapperFields for returning your fields:

export async function getInputs(this: ILoadOptionsFunctions): Promise<ResourceMapperFields> {
	const inputs  = ...howeveryougetinputs;

	return {
		fields: inputs.map(input => (
			{
				id: input.name,
				displayName: input.fullName,
				defaultMatch: true,
				canBeUsedToMatch: true,
				required: input.required,
				display: true,
				type: input.type,
			}
		))
	}
}
2 Likes