mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add custom fields to all create-update ops
This commit is contained in:
parent
b4c265aa08
commit
eb869cd622
|
@ -65,7 +65,6 @@ export async function zohoApiRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(options);
|
|
||||||
const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
|
const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
|
||||||
|
|
||||||
if (responseData === undefined) return [];
|
if (responseData === undefined) return [];
|
||||||
|
@ -295,10 +294,19 @@ export const toLoadOptions = (items: ResourceItems, nameProperty: NameType) =>
|
||||||
/**
|
/**
|
||||||
* Retrieve all fields for a resource, sorted alphabetically.
|
* 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 endpoint = '/settings/fields';
|
||||||
const qs = { module: `${resource}s` };
|
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 }));
|
const options = fields.map(({ field_label, api_name }) => ({ name: field_label, value: api_name }));
|
||||||
|
|
||||||
return sortBy(options, o => o.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);
|
Object.assign(qs, fields && { fields: fields.join(',') }, rest);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const capitalizeInitial = (str: string) => str[0].toUpperCase() + str.slice(1);
|
||||||
|
|
|
@ -193,6 +193,8 @@ export class ZohoCrm implements INodeType {
|
||||||
// resource fields
|
// resource fields
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
|
// standard fields
|
||||||
|
|
||||||
async getAccountFields(this: ILoadOptionsFunctions) {
|
async getAccountFields(this: ILoadOptionsFunctions) {
|
||||||
return getFields.call(this, 'account');
|
return getFields.call(this, 'account');
|
||||||
},
|
},
|
||||||
|
@ -236,6 +238,52 @@ export class ZohoCrm implements INodeType {
|
||||||
async getVendorFields(this: ILoadOptionsFunctions) {
|
async getVendorFields(this: ILoadOptionsFunctions) {
|
||||||
return getFields.call(this, 'vendor');
|
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 });
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
billingAddress,
|
billingAddress,
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
shippingAddress,
|
shippingAddress,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
@ -130,6 +131,7 @@ export const accountFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('account'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
@ -316,6 +318,7 @@ export const accountFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('account'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mailingAddress,
|
mailingAddress,
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
otherAddress,
|
otherAddress,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
@ -112,6 +113,7 @@ export const contactFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('contact'),
|
||||||
{
|
{
|
||||||
displayName: 'Date of Birth',
|
displayName: 'Date of Birth',
|
||||||
name: 'Date_of_Birth',
|
name: 'Date_of_Birth',
|
||||||
|
@ -322,6 +324,7 @@ export const contactFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('contact'),
|
||||||
{
|
{
|
||||||
displayName: 'Date of Birth',
|
displayName: 'Date of Birth',
|
||||||
name: 'Date_of_Birth',
|
name: 'Date_of_Birth',
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
|
||||||
|
@ -127,6 +128,7 @@ export const dealFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('deal'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
@ -282,6 +284,7 @@ export const dealFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('deal'),
|
||||||
{
|
{
|
||||||
displayName: 'Deal Name',
|
displayName: 'Deal Name',
|
||||||
name: 'Deal_Name',
|
name: 'Deal_Name',
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
billingAddress,
|
billingAddress,
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
makeProductDetails,
|
makeProductDetails,
|
||||||
shippingAddress,
|
shippingAddress,
|
||||||
|
@ -119,6 +120,7 @@ export const invoiceFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('invoice'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
@ -307,6 +309,7 @@ export const invoiceFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('invoice'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
address,
|
address,
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
|
||||||
|
@ -124,6 +125,7 @@ export const leadFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('lead'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
@ -355,6 +357,7 @@ export const leadFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('lead'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
|
||||||
|
@ -98,6 +99,7 @@ export const productFields = [
|
||||||
},
|
},
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('product'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
@ -254,6 +256,7 @@ export const productFields = [
|
||||||
},
|
},
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('product'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
billingAddress,
|
billingAddress,
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
makeProductDetails,
|
makeProductDetails,
|
||||||
shippingAddress,
|
shippingAddress,
|
||||||
|
@ -184,6 +185,7 @@ export const purchaseOrderFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('purchaseOrder'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
@ -405,6 +407,7 @@ export const purchaseOrderFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('purchaseOrder'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
billingAddress,
|
billingAddress,
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
makeProductDetails,
|
makeProductDetails,
|
||||||
shippingAddress,
|
shippingAddress,
|
||||||
|
@ -118,6 +119,7 @@ export const quoteFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('quote'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
@ -306,6 +308,7 @@ export const quoteFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('quote'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
billingAddress,
|
billingAddress,
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
makeProductDetails,
|
makeProductDetails,
|
||||||
shippingAddress,
|
shippingAddress,
|
||||||
|
@ -149,6 +150,7 @@ export const salesOrderFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('salesOrder'),
|
||||||
{
|
{
|
||||||
displayName: 'Deal ID',
|
displayName: 'Deal ID',
|
||||||
name: 'dealId',
|
name: 'dealId',
|
||||||
|
@ -385,6 +387,7 @@ export const salesOrderFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Symbol of the currency in which revenue is generated.',
|
description: 'Symbol of the currency in which revenue is generated.',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('salesOrder'),
|
||||||
{
|
{
|
||||||
displayName: 'Deal ID',
|
displayName: 'Deal ID',
|
||||||
name: 'dealId',
|
name: 'dealId',
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { capitalizeInitial } from '../GenericFunctions';
|
||||||
import { CamelCaseResource } from '../types';
|
import { CamelCaseResource } from '../types';
|
||||||
|
|
||||||
export const billingAddress = {
|
export const billingAddress = {
|
||||||
|
@ -313,18 +314,7 @@ export const makeProductDetails = (resource: CamelCaseResource) => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const makeGetAllFields = (resource: CamelCaseResource) => {
|
export const makeGetAllFields = (resource: CamelCaseResource) => {
|
||||||
const loadOptionsMethod = {
|
const loadOptionsMethod = `get${capitalizeInitial(resource)}Fields`;
|
||||||
account: 'getAccountFields',
|
|
||||||
contact: 'getContactFields',
|
|
||||||
deal: 'getDealFields',
|
|
||||||
invoice: 'getInvoiceFields',
|
|
||||||
lead: 'getLeadFields',
|
|
||||||
product: 'getProductFields',
|
|
||||||
purchaseOrder: 'getPurchaseOrderFields',
|
|
||||||
quote: 'getQuoteFields',
|
|
||||||
salesOrder: 'getSalesOrderFields',
|
|
||||||
vendor: 'getVendorFields',
|
|
||||||
}[resource];
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
@ -407,6 +397,7 @@ export const makeGetAllFields = (resource: CamelCaseResource) => {
|
||||||
loadOptionsMethod,
|
loadOptionsMethod,
|
||||||
},
|
},
|
||||||
default: [],
|
default: [],
|
||||||
|
description: 'Return only these fields.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Include Child',
|
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.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
address,
|
address,
|
||||||
|
makeCustomFieldsFixedCollection,
|
||||||
makeGetAllFields,
|
makeGetAllFields,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
|
||||||
|
@ -103,6 +104,7 @@ export const vendorFields = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('vendor'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
@ -230,6 +232,7 @@ export const vendorFields = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
makeCustomFieldsFixedCollection('vendor'),
|
||||||
{
|
{
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'Description',
|
name: 'Description',
|
||||||
|
|
1
packages/nodes-base/nodes/Zoho/types.d.ts
vendored
1
packages/nodes-base/nodes/Zoho/types.d.ts
vendored
|
@ -74,6 +74,7 @@ export type LoadedFields = {
|
||||||
fields: Array<{
|
fields: Array<{
|
||||||
field_label: string;
|
field_label: string;
|
||||||
api_name: string;
|
api_name: string;
|
||||||
|
custom_field: boolean;
|
||||||
}>
|
}>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue