mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
⚡ Add record type id to supported objects on Salesforce Node (#2056)
This commit is contained in:
parent
fa31c0c7b6
commit
244a2ba409
|
@ -291,6 +291,15 @@ export const accountFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Phone number for the account.',
|
description: 'Phone number for the account.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'SicDesc',
|
displayName: 'SicDesc',
|
||||||
name: 'sicDesc',
|
name: 'sicDesc',
|
||||||
|
@ -539,6 +548,15 @@ export const accountFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Phone number for the account.',
|
description: 'Phone number for the account.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Type',
|
displayName: 'Type',
|
||||||
name: 'type',
|
name: 'type',
|
||||||
|
|
|
@ -208,6 +208,15 @@ export const caseFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The reason why the case was created, such as Instructions not clear, or User didn’t attend training.',
|
description: 'The reason why the case was created, such as Instructions not clear, or User didn’t attend training.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Status',
|
displayName: 'Status',
|
||||||
name: 'status',
|
name: 'status',
|
||||||
|
@ -405,6 +414,15 @@ export const caseFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The reason why the case was created, such as Instructions not clear, or User didn’t attend training.',
|
description: 'The reason why the case was created, such as Instructions not clear, or User didn’t attend training.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Status',
|
displayName: 'Status',
|
||||||
name: 'status',
|
name: 'status',
|
||||||
|
|
|
@ -16,6 +16,7 @@ export interface ICase {
|
||||||
SuppliedEmail?: string;
|
SuppliedEmail?: string;
|
||||||
SuppliedPhone?: string;
|
SuppliedPhone?: string;
|
||||||
SuppliedCompany?: string;
|
SuppliedCompany?: string;
|
||||||
|
RecordTypeId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICaseComment {
|
export interface ICaseComment {
|
||||||
|
|
|
@ -384,6 +384,15 @@ export const contactFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Phone number for the contact.',
|
description: 'Phone number for the contact.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Salutation',
|
displayName: 'Salutation',
|
||||||
name: 'salutation',
|
name: 'salutation',
|
||||||
|
@ -680,6 +689,15 @@ export const contactFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Phone number for the contact.',
|
description: 'Phone number for the contact.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Salutation',
|
displayName: 'Salutation',
|
||||||
name: 'salutation',
|
name: 'salutation',
|
||||||
|
|
|
@ -512,4 +512,67 @@ export const customObjectFields = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
'upsert',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'customObject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
loadOptionsDependsOn: [
|
||||||
|
'customObject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Update Fields',
|
||||||
|
name: 'updateFields',
|
||||||
|
type: 'collection',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'update',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'customObject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
loadOptionsDependsOn: [
|
||||||
|
'customObject',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -320,6 +320,15 @@ export const leadFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Postal code for the address of the lead. Label is Zip/Postal Code.',
|
description: 'Postal code for the address of the lead. Label is Zip/Postal Code.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Rating',
|
displayName: 'Rating',
|
||||||
name: 'rating',
|
name: 'rating',
|
||||||
|
@ -578,6 +587,15 @@ export const leadFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Phone number for the lead.',
|
description: 'Phone number for the lead.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Record Type ID',
|
||||||
|
name: 'recordTypeId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getRecordTypes',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Rating',
|
displayName: 'Rating',
|
||||||
name: 'rating',
|
name: 'rating',
|
||||||
|
|
|
@ -121,6 +121,7 @@ import {
|
||||||
import {
|
import {
|
||||||
LoggerProxy as Logger,
|
LoggerProxy as Logger,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
import { query } from '../Elasticsearch/descriptions/placeholders';
|
||||||
|
|
||||||
export class Salesforce implements INodeType {
|
export class Salesforce implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -408,7 +409,6 @@ export class Salesforce implements INodeType {
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
|
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
|
||||||
const { fields } = await salesforceApiRequest.call(this, 'GET', `/sobjects/${resource}/describe`);
|
const { fields } = await salesforceApiRequest.call(this, 'GET', `/sobjects/${resource}/describe`);
|
||||||
|
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
if (field.custom === true) {
|
if (field.custom === true) {
|
||||||
const fieldName = field.label;
|
const fieldName = field.label;
|
||||||
|
@ -422,6 +422,29 @@ export class Salesforce implements INodeType {
|
||||||
sortOptions(returnData);
|
sortOptions(returnData);
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
|
// Get all the record types to display them to user so that he can
|
||||||
|
// select them easily
|
||||||
|
async getRecordTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
let resource = this.getNodeParameter('resource', 0) as string;
|
||||||
|
if (resource === 'customObject') {
|
||||||
|
resource = this.getNodeParameter('customObject', 0) as string;
|
||||||
|
}
|
||||||
|
const qs = {
|
||||||
|
q: `SELECT Id, Name, SobjectType, IsActive FROM RecordType WHERE SobjectType = '${resource}'`,
|
||||||
|
};
|
||||||
|
const types = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs);
|
||||||
|
for (const type of types) {
|
||||||
|
if (type.IsActive === true) {
|
||||||
|
returnData.push({
|
||||||
|
name: type.Name,
|
||||||
|
value: type.Id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sortOptions(returnData);
|
||||||
|
return returnData;
|
||||||
|
},
|
||||||
// Get all the external id fields to display them to user so that he can
|
// Get all the external id fields to display them to user so that he can
|
||||||
// select them easily
|
// select them easily
|
||||||
async getExternalIdFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getExternalIdFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
@ -1061,6 +1084,9 @@ export class Salesforce implements INodeType {
|
||||||
if (additionalFields.mobilePhone !== undefined) {
|
if (additionalFields.mobilePhone !== undefined) {
|
||||||
body.MobilePhone = additionalFields.mobilePhone as string;
|
body.MobilePhone = additionalFields.mobilePhone as string;
|
||||||
}
|
}
|
||||||
|
if (additionalFields.recordTypeId !== undefined) {
|
||||||
|
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (additionalFields.customFieldsUi) {
|
if (additionalFields.customFieldsUi) {
|
||||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||||
if (customFields) {
|
if (customFields) {
|
||||||
|
@ -1163,6 +1189,9 @@ export class Salesforce implements INodeType {
|
||||||
if (updateFields.mobilePhone !== undefined) {
|
if (updateFields.mobilePhone !== undefined) {
|
||||||
body.MobilePhone = updateFields.mobilePhone as string;
|
body.MobilePhone = updateFields.mobilePhone as string;
|
||||||
}
|
}
|
||||||
|
if (updateFields.recordTypeId !== undefined) {
|
||||||
|
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (updateFields.customFieldsUi) {
|
if (updateFields.customFieldsUi) {
|
||||||
const customFields = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
const customFields = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||||
if (customFields) {
|
if (customFields) {
|
||||||
|
@ -1267,6 +1296,9 @@ export class Salesforce implements INodeType {
|
||||||
if (additionalFields.jigsaw !== undefined) {
|
if (additionalFields.jigsaw !== undefined) {
|
||||||
body.Jigsaw = additionalFields.jigsaw as string;
|
body.Jigsaw = additionalFields.jigsaw as string;
|
||||||
}
|
}
|
||||||
|
if (additionalFields.recordTypeId !== undefined) {
|
||||||
|
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (additionalFields.owner !== undefined) {
|
if (additionalFields.owner !== undefined) {
|
||||||
body.OwnerId = additionalFields.owner as string;
|
body.OwnerId = additionalFields.owner as string;
|
||||||
}
|
}
|
||||||
|
@ -1381,6 +1413,9 @@ export class Salesforce implements INodeType {
|
||||||
if (updateFields.email !== undefined) {
|
if (updateFields.email !== undefined) {
|
||||||
body.Email = updateFields.email as string;
|
body.Email = updateFields.email as string;
|
||||||
}
|
}
|
||||||
|
if (updateFields.recordTypeId !== undefined) {
|
||||||
|
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (updateFields.phone !== undefined) {
|
if (updateFields.phone !== undefined) {
|
||||||
body.Phone = updateFields.phone as string;
|
body.Phone = updateFields.phone as string;
|
||||||
}
|
}
|
||||||
|
@ -1551,6 +1586,7 @@ export class Salesforce implements INodeType {
|
||||||
if (operation === 'create' || operation === 'upsert') {
|
if (operation === 'create' || operation === 'upsert') {
|
||||||
const customObject = this.getNodeParameter('customObject', i) as string;
|
const customObject = this.getNodeParameter('customObject', i) as string;
|
||||||
const customFieldsUi = this.getNodeParameter('customFieldsUi', i) as IDataObject;
|
const customFieldsUi = this.getNodeParameter('customFieldsUi', i) as IDataObject;
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
const body: IDataObject = {};
|
const body: IDataObject = {};
|
||||||
if (customFieldsUi) {
|
if (customFieldsUi) {
|
||||||
const customFields = (customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
const customFields = (customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||||
|
@ -1561,6 +1597,9 @@ export class Salesforce implements INodeType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (additionalFields.recordTypeId) {
|
||||||
|
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||||
|
}
|
||||||
let endpoint = `/sobjects/${customObject}`;
|
let endpoint = `/sobjects/${customObject}`;
|
||||||
let method = 'POST';
|
let method = 'POST';
|
||||||
if (operation === 'upsert') {
|
if (operation === 'upsert') {
|
||||||
|
@ -1578,7 +1617,11 @@ export class Salesforce implements INodeType {
|
||||||
const recordId = this.getNodeParameter('recordId', i) as string;
|
const recordId = this.getNodeParameter('recordId', i) as string;
|
||||||
const customObject = this.getNodeParameter('customObject', i) as string;
|
const customObject = this.getNodeParameter('customObject', i) as string;
|
||||||
const customFieldsUi = this.getNodeParameter('customFieldsUi', i) as IDataObject;
|
const customFieldsUi = this.getNodeParameter('customFieldsUi', i) as IDataObject;
|
||||||
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||||
const body: IDataObject = {};
|
const body: IDataObject = {};
|
||||||
|
if (updateFields.recordTypeId) {
|
||||||
|
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (customFieldsUi) {
|
if (customFieldsUi) {
|
||||||
const customFields = (customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
const customFields = (customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||||
if (customFields) {
|
if (customFields) {
|
||||||
|
@ -1926,6 +1969,9 @@ export class Salesforce implements INodeType {
|
||||||
if (additionalFields.shippingPostalCode !== undefined) {
|
if (additionalFields.shippingPostalCode !== undefined) {
|
||||||
body.ShippingPostalCode = additionalFields.shippingPostalCode as string;
|
body.ShippingPostalCode = additionalFields.shippingPostalCode as string;
|
||||||
}
|
}
|
||||||
|
if (additionalFields.recordTypeId !== undefined) {
|
||||||
|
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (additionalFields.customFieldsUi) {
|
if (additionalFields.customFieldsUi) {
|
||||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||||
if (customFields) {
|
if (customFields) {
|
||||||
|
@ -1974,6 +2020,9 @@ export class Salesforce implements INodeType {
|
||||||
if (updateFields.sicDesc !== undefined) {
|
if (updateFields.sicDesc !== undefined) {
|
||||||
body.SicDesc = updateFields.sicDesc as string;
|
body.SicDesc = updateFields.sicDesc as string;
|
||||||
}
|
}
|
||||||
|
if (updateFields.recordTypeId !== undefined) {
|
||||||
|
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (updateFields.website !== undefined) {
|
if (updateFields.website !== undefined) {
|
||||||
body.Website = updateFields.website as string;
|
body.Website = updateFields.website as string;
|
||||||
}
|
}
|
||||||
|
@ -2145,6 +2194,9 @@ export class Salesforce implements INodeType {
|
||||||
if (additionalFields.suppliedCompany !== undefined) {
|
if (additionalFields.suppliedCompany !== undefined) {
|
||||||
body.SuppliedCompany = additionalFields.suppliedCompany as string;
|
body.SuppliedCompany = additionalFields.suppliedCompany as string;
|
||||||
}
|
}
|
||||||
|
if (additionalFields.recordTypeId !== undefined) {
|
||||||
|
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (additionalFields.customFieldsUi) {
|
if (additionalFields.customFieldsUi) {
|
||||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||||
if (customFields) {
|
if (customFields) {
|
||||||
|
@ -2185,6 +2237,9 @@ export class Salesforce implements INodeType {
|
||||||
if (updateFields.accountId !== undefined) {
|
if (updateFields.accountId !== undefined) {
|
||||||
body.AccountId = updateFields.accountId as string;
|
body.AccountId = updateFields.accountId as string;
|
||||||
}
|
}
|
||||||
|
if (updateFields.recordTypeId !== undefined) {
|
||||||
|
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||||
|
}
|
||||||
if (updateFields.contactId !== undefined) {
|
if (updateFields.contactId !== undefined) {
|
||||||
body.ContactId = updateFields.contactId as string;
|
body.ContactId = updateFields.contactId as string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue