diff --git a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts index 68b9ecdfd5..eb3fd9b0a4 100644 --- a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts @@ -26,6 +26,7 @@ import { GetAllFilterOptions, IdType, LoadedFields, + LoadedLayouts, LocationType, NameType, ProductDetails, @@ -327,19 +328,7 @@ export async function getFields( resource: SnakeCaseResource, { onlyCustom } = { onlyCustom: false }, ) { - const moduleMap: { [resource: string]: string } = { - account: 'Accounts', - contact: 'Contacts', - deal: 'Deals', - invoice: 'Invoices', - lead: 'Leads', - product: 'Products', - purchaseOrder: 'Purchase_Orders', - salesOrder: 'Sales_Orders', - vendor: 'Vendors', - }; - - const qs = { module: moduleMap[resource] }; + const qs = { module: getModuleName(resource) }; let { fields } = await zohoApiRequest.call(this, 'GET', '/settings/fields', {}, qs) as LoadedFields; @@ -352,6 +341,49 @@ export async function getFields( return sortBy(options, o => o.name); } +function getModuleName(resource: string) { + return { + account: 'Accounts', + contact: 'Contacts', + deal: 'Deals', + invoice: 'Invoices', + lead: 'Leads', + product: 'Products', + purchaseOrder: 'Purchase_Orders', + salesOrder: 'Sales_Orders', + vendor: 'Vendors', + quote: 'Quotes', + }[resource]; +} + +export async function getPicklistOptions( + this: ILoadOptionsFunctions, + resource: string, + targetField: string, +) { + const qs = { module: getModuleName(resource) }; + const responseData = await zohoApiRequest.call(this, 'GET', '/settings/layouts', {}, qs) as LoadedLayouts; + + const pickListOptions = responseData.layouts[0] + .sections.find(section => section.api_name === getSectionApiName(resource)) + ?.fields.find(f => f.api_name === targetField) + ?.pick_list_values; + + if (!pickListOptions) return []; + + return pickListOptions.map( + (option) => ({ name: option.display_value, value: option.actual_value }), + ); +} + + +function getSectionApiName(resource: string) { + if (resource === 'purchaseOrder') return 'Purchase Order Information'; + if (resource === 'salesOrder') return 'Sales Order Information'; + + return `${capitalizeInitial(resource)} Information`; +} + /** * Add filter options to a query string object. */ diff --git a/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts b/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts index 790e7a8d39..984836eb6b 100644 --- a/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts +++ b/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts @@ -24,6 +24,7 @@ import { adjustSalesOrderPayload, adjustVendorPayload, getFields, + getPicklistOptions, handleListing, throwOnEmptyUpdate, toLoadOptions, @@ -194,7 +195,7 @@ export class ZohoCrm implements INodeType { // resource fields // ---------------------------------------- - // standard fields + // standard fields - called from `makeGetAllFields` async getAccountFields(this: ILoadOptionsFunctions) { return getFields.call(this, 'account'); @@ -285,6 +286,30 @@ export class ZohoCrm implements INodeType { async getCustomVendorFields(this: ILoadOptionsFunctions) { return getFields.call(this, 'vendor', { onlyCustom: true }); }, + + // ---------------------------------------- + // resource picklist options + // ---------------------------------------- + + async getAccountType(this: ILoadOptionsFunctions) { + return getPicklistOptions.call(this, 'account', 'Account_Type'); + }, + + async getDealStage(this: ILoadOptionsFunctions) { + return getPicklistOptions.call(this, 'deal', 'Stage'); + }, + + async getPurchaseOrderStatus(this: ILoadOptionsFunctions) { + return getPicklistOptions.call(this, 'purchaseOrder', 'Status'); + }, + + async getSalesOrderStatus(this: ILoadOptionsFunctions) { + return getPicklistOptions.call(this, 'salesOrder', 'Status'); + }, + + async getQuoteStage(this: ILoadOptionsFunctions) { + return getPicklistOptions.call(this, 'quote', 'Quote_Stage'); + }, }, }; diff --git a/packages/nodes-base/nodes/Zoho/descriptions/AccountDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/AccountDescription.ts index 09cc1e1b60..397cd10afe 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/AccountDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/AccountDescription.ts @@ -135,8 +135,11 @@ export const accountFields = [ { displayName: 'Account Type', name: 'Account_Type', - type: 'string', - default: '', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getAccountType', + }, + default: [], }, { displayName: 'Annual Revenue', @@ -323,8 +326,11 @@ export const accountFields = [ { displayName: 'Account Type', name: 'Account_Type', - type: 'string', - default: '', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getAccountType', + }, + default: [], }, { displayName: 'Annual Revenue', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/DealDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/DealDescription.ts index f0472ad301..3f55fd61df 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/DealDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/DealDescription.ts @@ -102,9 +102,12 @@ export const dealFields = [ { displayName: 'Stage', name: 'stage', - type: 'string', + type: 'options', required: true, - default: '', + default: [], + typeOptions: { + loadOptionsMethod: 'getDealStage', + }, displayOptions: { show: { resource: [ @@ -367,8 +370,11 @@ export const dealFields = [ { displayName: 'Stage', name: 'Stage', - type: 'string', - default: '', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getDealStage', + }, + default: [], }, ], }, diff --git a/packages/nodes-base/nodes/Zoho/descriptions/PurchaseOrderDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/PurchaseOrderDescription.ts index f860ad99a5..f34098259e 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/PurchaseOrderDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/PurchaseOrderDescription.ts @@ -284,8 +284,11 @@ export const purchaseOrderFields = [ { displayName: 'Status', name: 'Status', - type: 'string', - default: '', + type: 'options', + default: [], + typeOptions: { + loadOptionsMethod: 'getPurchaseOrderStatus', + }, description: 'Status of the purchase order.', }, { @@ -508,8 +511,11 @@ export const purchaseOrderFields = [ { displayName: 'Status', name: 'Status', - type: 'string', - default: '', + type: 'options', + default: [], + typeOptions: { + loadOptionsMethod: 'getPurchaseOrderStatus', + }, description: 'Status of the purchase order.', }, { diff --git a/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts index 3aff56cbd2..694ed96044 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts @@ -177,8 +177,12 @@ export const quoteFields = [ { displayName: 'Quote Stage', name: 'Quote_Stage', - type: 'string', - default: '', + type: 'options', + default: [], + typeOptions: { + loadOptionsMethod: 'getQuoteStage', + }, + description: 'Stage of the quote.', }, shippingAddress, { @@ -367,8 +371,12 @@ export const quoteFields = [ { displayName: 'Quote Stage', name: 'Quote_Stage', - type: 'string', - default: '', + type: 'options', + default: [], + typeOptions: { + loadOptionsMethod: 'getQuoteStage', + }, + description: 'Stage of the quote.', }, shippingAddress, { diff --git a/packages/nodes-base/nodes/Zoho/descriptions/SalesOrderDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/SalesOrderDescription.ts index ec8f2293ce..9ac4722a2c 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/SalesOrderDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/SalesOrderDescription.ts @@ -255,8 +255,11 @@ export const salesOrderFields = [ { displayName: 'Status', name: 'Status', - type: 'string', - default: '', + type: 'options', + default: [], + typeOptions: { + loadOptionsMethod: 'getSalesOrderStatus', + }, description: 'Status of the sales order.', }, { @@ -493,8 +496,11 @@ export const salesOrderFields = [ { displayName: 'Status', name: 'Status', - type: 'string', - default: '', + type: 'options', + default: [], + typeOptions: { + loadOptionsMethod: 'getSalesOrderStatus', + }, description: 'Status of the sales order.', }, { diff --git a/packages/nodes-base/nodes/Zoho/types.d.ts b/packages/nodes-base/nodes/Zoho/types.d.ts index 229d4ddf97..f8f9be44fa 100644 --- a/packages/nodes-base/nodes/Zoho/types.d.ts +++ b/packages/nodes-base/nodes/Zoho/types.d.ts @@ -85,3 +85,18 @@ export type LoadedProducts = Array<{ Product_Name: string; id: string; }>; + +export type LoadedLayouts = { + layouts: Array<{ + sections: Array<{ + api_name: string; + fields: Array<{ + api_name: string; + pick_list_values: Array<{ + display_value: string; + actual_value: string; + }> + }> + }> + }> +}