diff --git a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts index 34b6269b16..f1e090ee77 100644 --- a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts @@ -65,7 +65,6 @@ export async function zohoApiRequest( } try { - console.log(options); const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options); if (responseData === undefined) return []; @@ -295,10 +294,19 @@ export const toLoadOptions = (items: ResourceItems, nameProperty: NameType) => /** * Retrieve all fields for a resource, sorted alphabetically. */ -export async function getFields(this: ILoadOptionsFunctions, resource: SnakeCaseResource) { +export async function getFields( + this: ILoadOptionsFunctions, + resource: SnakeCaseResource, + { onlyCustom } = { onlyCustom: false }, +) { const endpoint = '/settings/fields'; const qs = { module: `${resource}s` }; - const { fields } = await zohoApiRequest.call(this, 'GET', endpoint, {}, qs) as LoadedFields; + let { fields } = await zohoApiRequest.call(this, 'GET', endpoint, {}, qs) as LoadedFields; + + if (onlyCustom) { + fields = fields.filter(({ custom_field }) => custom_field); + } + const options = fields.map(({ field_label, api_name }) => ({ name: field_label, value: api_name })); return sortBy(options, o => o.name); @@ -313,3 +321,5 @@ export const addGetAllFilterOptions = (qs: IDataObject, options: GetAllFilterOpt Object.assign(qs, fields && { fields: fields.join(',') }, rest); } }; + +export const capitalizeInitial = (str: string) => str[0].toUpperCase() + str.slice(1); diff --git a/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts b/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts index ff13266c70..cc7b871a65 100644 --- a/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts +++ b/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts @@ -193,6 +193,8 @@ export class ZohoCrm implements INodeType { // resource fields // ---------------------------------------- + // standard fields + async getAccountFields(this: ILoadOptionsFunctions) { return getFields.call(this, 'account'); }, @@ -236,6 +238,52 @@ export class ZohoCrm implements INodeType { async getVendorFields(this: ILoadOptionsFunctions) { return getFields.call(this, 'vendor'); }, + + // custom fields + + async getCustomAccountFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'account', { onlyCustom: true }); + }, + + async getCustomContactFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'contact', { onlyCustom: true }); + }, + + async getCustomDealFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'deal', { onlyCustom: true }); + }, + + async getCustomInvoiceFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'invoice', { onlyCustom: true }); + }, + + async getCustomLeadFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'lead', { onlyCustom: true }); + }, + + async getCustomProductFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'product', { onlyCustom: true }); + }, + + async getCustomPurchaseOrderFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'purchase_order', { onlyCustom: true }); + }, + + async getCustomVendorOrderFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'vendor', { onlyCustom: true }); + }, + + async getCustomQuoteFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'quote', { onlyCustom: true }); + }, + + async getCustomSalesOrderFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'sales_order', { onlyCustom: true }); + }, + + async getCustomVendorFields(this: ILoadOptionsFunctions) { + return getFields.call(this, 'vendor', { onlyCustom: true }); + }, }, }; diff --git a/packages/nodes-base/nodes/Zoho/descriptions/AccountDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/AccountDescription.ts index 20807bf2d1..c13f1619de 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/AccountDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/AccountDescription.ts @@ -4,6 +4,7 @@ import { import { billingAddress, + makeCustomFieldsFixedCollection, makeGetAllFields, shippingAddress, } from './SharedFields'; @@ -130,6 +131,7 @@ export const accountFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('account'), { displayName: 'Description', name: 'Description', @@ -316,6 +318,7 @@ export const accountFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('account'), { displayName: 'Description', name: 'Description', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/ContactDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/ContactDescription.ts index d4b11462a5..e163c22f01 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/ContactDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/ContactDescription.ts @@ -4,6 +4,7 @@ import { import { mailingAddress, + makeCustomFieldsFixedCollection, makeGetAllFields, otherAddress, } from './SharedFields'; @@ -112,6 +113,7 @@ export const contactFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('contact'), { displayName: 'Date of Birth', name: 'Date_of_Birth', @@ -322,6 +324,7 @@ export const contactFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('contact'), { displayName: 'Date of Birth', name: 'Date_of_Birth', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/DealDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/DealDescription.ts index c0019cb568..f1a5709332 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/DealDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/DealDescription.ts @@ -3,6 +3,7 @@ import { } from 'n8n-workflow'; import { + makeCustomFieldsFixedCollection, makeGetAllFields, } from './SharedFields'; @@ -127,6 +128,7 @@ export const dealFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('deal'), { displayName: 'Description', name: 'Description', @@ -282,6 +284,7 @@ export const dealFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('deal'), { displayName: 'Deal Name', name: 'Deal_Name', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/InvoiceDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/InvoiceDescription.ts index f476aca2c1..00a4453d99 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/InvoiceDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/InvoiceDescription.ts @@ -4,6 +4,7 @@ import { import { billingAddress, + makeCustomFieldsFixedCollection, makeGetAllFields, makeProductDetails, shippingAddress, @@ -119,6 +120,7 @@ export const invoiceFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('invoice'), { displayName: 'Description', name: 'Description', @@ -307,6 +309,7 @@ export const invoiceFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('invoice'), { displayName: 'Description', name: 'Description', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/LeadDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/LeadDescription.ts index e3d9371b2b..d348c6539d 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/LeadDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/LeadDescription.ts @@ -4,6 +4,7 @@ import { import { address, + makeCustomFieldsFixedCollection, makeGetAllFields, } from './SharedFields'; @@ -124,6 +125,7 @@ export const leadFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('lead'), { displayName: 'Description', name: 'Description', @@ -355,6 +357,7 @@ export const leadFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('lead'), { displayName: 'Description', name: 'Description', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/ProductDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/ProductDescription.ts index 79cdb2d33f..7cbc398c3f 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/ProductDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/ProductDescription.ts @@ -3,6 +3,7 @@ import { } from 'n8n-workflow'; import { + makeCustomFieldsFixedCollection, makeGetAllFields, } from './SharedFields'; @@ -98,6 +99,7 @@ export const productFields = [ }, default: 0, }, + makeCustomFieldsFixedCollection('product'), { displayName: 'Description', name: 'Description', @@ -254,6 +256,7 @@ export const productFields = [ }, default: 0, }, + makeCustomFieldsFixedCollection('product'), { displayName: 'Description', name: 'Description', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/PurchaseOrderDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/PurchaseOrderDescription.ts index c8059fe543..6db300f74f 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/PurchaseOrderDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/PurchaseOrderDescription.ts @@ -4,6 +4,7 @@ import { import { billingAddress, + makeCustomFieldsFixedCollection, makeGetAllFields, makeProductDetails, shippingAddress, @@ -184,6 +185,7 @@ export const purchaseOrderFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('purchaseOrder'), { displayName: 'Description', name: 'Description', @@ -405,6 +407,7 @@ export const purchaseOrderFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('purchaseOrder'), { displayName: 'Description', name: 'Description', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts index ce72030e16..e0f5ca7a99 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts @@ -4,6 +4,7 @@ import { import { billingAddress, + makeCustomFieldsFixedCollection, makeGetAllFields, makeProductDetails, shippingAddress, @@ -118,6 +119,7 @@ export const quoteFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('quote'), { displayName: 'Description', name: 'Description', @@ -306,6 +308,7 @@ export const quoteFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('quote'), { displayName: 'Description', name: 'Description', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/SalesOrderDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/SalesOrderDescription.ts index 991f2caa12..59739744d1 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/SalesOrderDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/SalesOrderDescription.ts @@ -4,6 +4,7 @@ import { import { billingAddress, + makeCustomFieldsFixedCollection, makeGetAllFields, makeProductDetails, shippingAddress, @@ -149,6 +150,7 @@ export const salesOrderFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('salesOrder'), { displayName: 'Deal ID', name: 'dealId', @@ -385,6 +387,7 @@ export const salesOrderFields = [ default: '', description: 'Symbol of the currency in which revenue is generated.', }, + makeCustomFieldsFixedCollection('salesOrder'), { displayName: 'Deal ID', name: 'dealId', diff --git a/packages/nodes-base/nodes/Zoho/descriptions/SharedFields.ts b/packages/nodes-base/nodes/Zoho/descriptions/SharedFields.ts index b605b5dc02..60d2ca64f8 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/SharedFields.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/SharedFields.ts @@ -1,3 +1,4 @@ +import { capitalizeInitial } from '../GenericFunctions'; import { CamelCaseResource } from '../types'; export const billingAddress = { @@ -313,18 +314,7 @@ export const makeProductDetails = (resource: CamelCaseResource) => ({ }); export const makeGetAllFields = (resource: CamelCaseResource) => { - const loadOptionsMethod = { - account: 'getAccountFields', - contact: 'getContactFields', - deal: 'getDealFields', - invoice: 'getInvoiceFields', - lead: 'getLeadFields', - product: 'getProductFields', - purchaseOrder: 'getPurchaseOrderFields', - quote: 'getQuoteFields', - salesOrder: 'getSalesOrderFields', - vendor: 'getVendorFields', - }[resource]; + const loadOptionsMethod = `get${capitalizeInitial(resource)}Fields`; return [ { @@ -407,6 +397,7 @@ export const makeGetAllFields = (resource: CamelCaseResource) => { loadOptionsMethod, }, default: [], + description: 'Return only these fields.', }, { displayName: 'Include Child', @@ -453,3 +444,44 @@ export const makeGetAllFields = (resource: CamelCaseResource) => { }, ]; }; + +export const makeCustomFieldsFixedCollection = (resource: CamelCaseResource) => { + const loadOptionsMethod = `getCustom${capitalizeInitial(resource)}Fields`; + + return { + displayName: 'Custom Fields', + name: 'customFields', + placeholder: 'Add Custom Field', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + description: 'Filter by custom fields.', + default: {}, + options: [ + { + name: 'customFields', + displayName: 'Custom Field', + values: [ + { + displayName: 'Field ID', + name: 'fieldId', + type: 'options', + typeOptions: { + loadOptionsMethod, + }, + default: '', + description: 'Custom field to set a value to.', + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + description: 'Value to set on custom field.', + }, + ], + }, + ], + }; +}; diff --git a/packages/nodes-base/nodes/Zoho/descriptions/VendorDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/VendorDescription.ts index 1e01750330..e8fd349a53 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/VendorDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/VendorDescription.ts @@ -4,6 +4,7 @@ import { import { address, + makeCustomFieldsFixedCollection, makeGetAllFields, } from './SharedFields'; @@ -103,6 +104,7 @@ export const vendorFields = [ type: 'string', default: '', }, + makeCustomFieldsFixedCollection('vendor'), { displayName: 'Description', name: 'Description', @@ -230,6 +232,7 @@ export const vendorFields = [ type: 'string', default: '', }, + makeCustomFieldsFixedCollection('vendor'), { displayName: 'Description', name: 'Description', diff --git a/packages/nodes-base/nodes/Zoho/types.d.ts b/packages/nodes-base/nodes/Zoho/types.d.ts index 461547111a..78970ce630 100644 --- a/packages/nodes-base/nodes/Zoho/types.d.ts +++ b/packages/nodes-base/nodes/Zoho/types.d.ts @@ -74,6 +74,7 @@ export type LoadedFields = { fields: Array<{ field_label: string; api_name: string; + custom_field: boolean; }> };