mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
⚡ Add record type id to supported objects on Salesforce Node (#2056)
This commit is contained in:
@@ -121,6 +121,7 @@ import {
|
||||
import {
|
||||
LoggerProxy as Logger,
|
||||
} from 'n8n-workflow';
|
||||
import { query } from '../Elasticsearch/descriptions/placeholders';
|
||||
|
||||
export class Salesforce implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -408,7 +409,6 @@ export class Salesforce implements INodeType {
|
||||
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
|
||||
const { fields } = await salesforceApiRequest.call(this, 'GET', `/sobjects/${resource}/describe`);
|
||||
|
||||
for (const field of fields) {
|
||||
if (field.custom === true) {
|
||||
const fieldName = field.label;
|
||||
@@ -422,6 +422,29 @@ export class Salesforce implements INodeType {
|
||||
sortOptions(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
|
||||
// select them easily
|
||||
async getExternalIdFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
@@ -1061,6 +1084,9 @@ export class Salesforce implements INodeType {
|
||||
if (additionalFields.mobilePhone !== undefined) {
|
||||
body.MobilePhone = additionalFields.mobilePhone as string;
|
||||
}
|
||||
if (additionalFields.recordTypeId !== undefined) {
|
||||
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||
}
|
||||
if (additionalFields.customFieldsUi) {
|
||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
if (customFields) {
|
||||
@@ -1163,6 +1189,9 @@ export class Salesforce implements INodeType {
|
||||
if (updateFields.mobilePhone !== undefined) {
|
||||
body.MobilePhone = updateFields.mobilePhone as string;
|
||||
}
|
||||
if (updateFields.recordTypeId !== undefined) {
|
||||
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||
}
|
||||
if (updateFields.customFieldsUi) {
|
||||
const customFields = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
if (customFields) {
|
||||
@@ -1267,6 +1296,9 @@ export class Salesforce implements INodeType {
|
||||
if (additionalFields.jigsaw !== undefined) {
|
||||
body.Jigsaw = additionalFields.jigsaw as string;
|
||||
}
|
||||
if (additionalFields.recordTypeId !== undefined) {
|
||||
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||
}
|
||||
if (additionalFields.owner !== undefined) {
|
||||
body.OwnerId = additionalFields.owner as string;
|
||||
}
|
||||
@@ -1381,6 +1413,9 @@ export class Salesforce implements INodeType {
|
||||
if (updateFields.email !== undefined) {
|
||||
body.Email = updateFields.email as string;
|
||||
}
|
||||
if (updateFields.recordTypeId !== undefined) {
|
||||
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||
}
|
||||
if (updateFields.phone !== undefined) {
|
||||
body.Phone = updateFields.phone as string;
|
||||
}
|
||||
@@ -1551,6 +1586,7 @@ export class Salesforce implements INodeType {
|
||||
if (operation === 'create' || operation === 'upsert') {
|
||||
const customObject = this.getNodeParameter('customObject', i) as string;
|
||||
const customFieldsUi = this.getNodeParameter('customFieldsUi', i) as IDataObject;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
const body: IDataObject = {};
|
||||
if (customFieldsUi) {
|
||||
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 method = 'POST';
|
||||
if (operation === 'upsert') {
|
||||
@@ -1578,7 +1617,11 @@ export class Salesforce implements INodeType {
|
||||
const recordId = this.getNodeParameter('recordId', i) as string;
|
||||
const customObject = this.getNodeParameter('customObject', i) as string;
|
||||
const customFieldsUi = this.getNodeParameter('customFieldsUi', i) as IDataObject;
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
const body: IDataObject = {};
|
||||
if (updateFields.recordTypeId) {
|
||||
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||
}
|
||||
if (customFieldsUi) {
|
||||
const customFields = (customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
if (customFields) {
|
||||
@@ -1926,6 +1969,9 @@ export class Salesforce implements INodeType {
|
||||
if (additionalFields.shippingPostalCode !== undefined) {
|
||||
body.ShippingPostalCode = additionalFields.shippingPostalCode as string;
|
||||
}
|
||||
if (additionalFields.recordTypeId !== undefined) {
|
||||
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||
}
|
||||
if (additionalFields.customFieldsUi) {
|
||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
if (customFields) {
|
||||
@@ -1974,6 +2020,9 @@ export class Salesforce implements INodeType {
|
||||
if (updateFields.sicDesc !== undefined) {
|
||||
body.SicDesc = updateFields.sicDesc as string;
|
||||
}
|
||||
if (updateFields.recordTypeId !== undefined) {
|
||||
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||
}
|
||||
if (updateFields.website !== undefined) {
|
||||
body.Website = updateFields.website as string;
|
||||
}
|
||||
@@ -2145,6 +2194,9 @@ export class Salesforce implements INodeType {
|
||||
if (additionalFields.suppliedCompany !== undefined) {
|
||||
body.SuppliedCompany = additionalFields.suppliedCompany as string;
|
||||
}
|
||||
if (additionalFields.recordTypeId !== undefined) {
|
||||
body.RecordTypeId = additionalFields.recordTypeId as string;
|
||||
}
|
||||
if (additionalFields.customFieldsUi) {
|
||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
if (customFields) {
|
||||
@@ -2185,6 +2237,9 @@ export class Salesforce implements INodeType {
|
||||
if (updateFields.accountId !== undefined) {
|
||||
body.AccountId = updateFields.accountId as string;
|
||||
}
|
||||
if (updateFields.recordTypeId !== undefined) {
|
||||
body.RecordTypeId = updateFields.recordTypeId as string;
|
||||
}
|
||||
if (updateFields.contactId !== undefined) {
|
||||
body.ContactId = updateFields.contactId as string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user