From 2d8fe3a4a51178e8627f92de8c6b250ce36a75ae Mon Sep 17 00:00:00 2001 From: Romain Dunand Date: Sat, 6 Feb 2021 16:42:07 +0100 Subject: [PATCH] :bug: Fix script list parsing on Filemaker Node(#1342) Scripts in sub folders where not detected --- .../nodes/FileMaker/GenericFunctions.ts | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts b/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts index 633a3f3b68..d11047b41b 100644 --- a/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts +++ b/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts @@ -24,6 +24,12 @@ interface LayoutObject { folderLayoutNames?:LayoutObject[]; } +interface ScriptObject { + name: string; + isFolder?: boolean; + folderScriptNames?:LayoutObject[]; +} + /** * Make an API request to ActiveCampaign * @@ -106,7 +112,6 @@ export async function getFields(this: ILoadOptionsFunctions): Promise { // try { const responseData = await this.helpers.request!(options); return responseData.response.fieldMetaData; - } catch (error) { // If that data does not exist for some reason return the actual error throw error; @@ -177,7 +182,9 @@ export async function getScripts(this: ILoadOptionsFunctions): Promise { // try { const responseData = await this.helpers.request!(options); - return responseData.response.scripts; + const items = parseScriptsList(responseData.response.scripts); + items.sort((a, b) => a.name > b.name ? 0 : 1); + return items; } catch (error) { // If that data does not exist for some reason return the actual error @@ -185,6 +192,21 @@ export async function getScripts(this: ILoadOptionsFunctions): Promise { // } } +function parseScriptsList(scripts: ScriptObject[]): INodePropertyOptions[] { + const returnData: INodePropertyOptions[] = []; + for (const script of scripts) { + if (script.isFolder!) { + returnData.push(...parseScriptsList(script.folderScriptNames!)); + } else if (script.name !== '-') { + returnData.push({ + name: script.name, + value: script.name, + }); + } + } + return returnData; +} + export async function getToken(this: ILoadOptionsFunctions | IExecuteFunctions | IExecuteSingleFunctions): Promise { // tslint:disable-line:no-any const credentials = this.getCredentials('fileMaker'); if (credentials === undefined) {