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) {