Add record type id to supported objects on Salesforce Node (#2056)

This commit is contained in:
Ricardo Espinoza 2021-08-07 03:41:00 -04:00 committed by GitHub
parent fa31c0c7b6
commit 244a2ba409
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 192 additions and 1 deletions

View file

@ -291,6 +291,15 @@ export const accountFields = [
default: '',
description: 'Phone number for the account.',
},
{
displayName: 'Record Type ID',
name: 'recordTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getRecordTypes',
},
default: '',
},
{
displayName: 'SicDesc',
name: 'sicDesc',
@ -539,6 +548,15 @@ export const accountFields = [
default: '',
description: 'Phone number for the account.',
},
{
displayName: 'Record Type ID',
name: 'recordTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getRecordTypes',
},
default: '',
},
{
displayName: 'Type',
name: 'type',

View file

@ -208,6 +208,15 @@ export const caseFields = [
default: '',
description: 'The reason why the case was created, such as Instructions not clear, or User didnt attend training.',
},
{
displayName: 'Record Type ID',
name: 'recordTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getRecordTypes',
},
default: '',
},
{
displayName: 'Status',
name: 'status',
@ -405,6 +414,15 @@ export const caseFields = [
default: '',
description: 'The reason why the case was created, such as Instructions not clear, or User didnt attend training.',
},
{
displayName: 'Record Type ID',
name: 'recordTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getRecordTypes',
},
default: '',
},
{
displayName: 'Status',
name: 'status',

View file

@ -16,6 +16,7 @@ export interface ICase {
SuppliedEmail?: string;
SuppliedPhone?: string;
SuppliedCompany?: string;
RecordTypeId?: string;
}
export interface ICaseComment {

View file

@ -384,6 +384,15 @@ export const contactFields = [
default: '',
description: 'Phone number for the contact.',
},
{
displayName: 'Record Type ID',
name: 'recordTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getRecordTypes',
},
default: '',
},
{
displayName: 'Salutation',
name: 'salutation',
@ -680,6 +689,15 @@ export const contactFields = [
default: '',
description: 'Phone number for the contact.',
},
{
displayName: 'Record Type ID',
name: 'recordTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getRecordTypes',
},
default: '',
},
{
displayName: 'Salutation',
name: 'salutation',

View file

@ -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[];

View file

@ -320,6 +320,15 @@ export const leadFields = [
default: '',
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',
name: 'rating',
@ -578,6 +587,15 @@ export const leadFields = [
default: '',
description: 'Phone number for the lead.',
},
{
displayName: 'Record Type ID',
name: 'recordTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getRecordTypes',
},
default: '',
},
{
displayName: 'Rating',
name: 'rating',

View file

@ -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;
}