Skip to content

Commit

Permalink
⚡ Add custom fields for Salesforce case create/update and alphabetize…
Browse files Browse the repository at this point in the history
… fields for update (n8n-io#1688)
  • Loading branch information
camcelroy authored Apr 24, 2021
1 parent adad513 commit 9271e73
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 55 deletions.
182 changes: 127 additions & 55 deletions packages/nodes-base/nodes/Salesforce/CaseDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ export const caseFields = [
default: '',
description: 'ID of the associated Contact.',
},
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Field',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
description: 'Filter by custom fields ',
default: {},
options: [
{
name: 'customFieldsValues',
displayName: 'Custom Field',
values: [
{
displayName: 'Field ID',
name: 'fieldId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCustomFields',
},
default: '',
description: 'The ID of the field to add custom field to.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'The value to set on custom field.',
},
],
},
],
},
{
displayName: 'Description',
name: 'description',
Expand Down Expand Up @@ -259,44 +295,78 @@ export const caseFields = [
},
options: [
{
displayName: 'Type',
name: 'type',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCaseTypes',
},
displayName: 'Account ID',
name: 'accountId',
type: 'string',
default: '',
description: 'The type of case',
description: 'ID of the account associated with this case.',
},
{
displayName: 'Origin',
name: 'origin',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCaseOrigins',
},
displayName: 'Contact ID',
name: 'contactId',
type: 'string',
default: '',
description: 'The source of the case, such as Email, Phone, or Web. Label is Case Origin.',
description: 'ID of the associated Contact.',
},
{
displayName: 'Reason',
name: 'reason',
type: 'options',
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Field',
type: 'fixedCollection',
typeOptions: {
loadOptionsMethod: 'getCaseReasons',
multipleValues: true,
},
description: 'Filter by custom fields ',
default: {},
options: [
{
name: 'customFieldsValues',
displayName: 'Custom Field',
values: [
{
displayName: 'Field ID',
name: 'fieldId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCustomFields',
},
default: '',
description: 'The ID of the field to add custom field to.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'The value to set on custom field.',
},
],
},
],
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: 'The reason why the case was created, such as Instructions not clear, or User didn’t attend training.',
description: 'A text description of the case. Limit: 32 KB.',
},
{
displayName: 'Status',
name: 'status',
displayName: 'Is Escalated',
name: 'isEscalated',
type: 'boolean',
default: false,
description: 'Indicates whether the case has been escalated (true) or not.',
},
{
displayName: 'Origin',
name: 'origin',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCaseStatuses',
loadOptionsMethod: 'getCaseOrigins',
},
default: '',
description: 'The status of the case, such as “New,” “Closed,” or “Escalated.” This field directly controls the IsClosed flag',
description: 'The source of the case, such as Email, Phone, or Web. Label is Case Origin.',
},
{
displayName: 'Owner',
Expand All @@ -308,13 +378,6 @@ export const caseFields = [
default: '',
description: 'The owner of the case.',
},
{
displayName: 'Subject',
name: 'subject',
type: 'string',
default: '',
description: 'The subject of the case. Limit: 255 characters.',
},
{
displayName: 'Parent ID',
name: 'ParentId',
Expand All @@ -333,39 +396,38 @@ export const caseFields = [
description: 'The importance or urgency of the case, such as High, Medium, or Low.',
},
{
displayName: 'Account ID',
name: 'accountId',
type: 'string',
displayName: 'Reason',
name: 'reason',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCaseReasons',
},
default: '',
description: 'ID of the account associated with this case.',
description: 'The reason why the case was created, such as Instructions not clear, or User didn’t attend training.',
},
{
displayName: 'Contact ID',
name: 'contactId',
type: 'string',
displayName: 'Status',
name: 'status',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCaseStatuses',
},
default: '',
description: 'ID of the associated Contact.',
description: 'The status of the case, such as “New,” “Closed,” or “Escalated.” This field directly controls the IsClosed flag',
},
{
displayName: 'Description',
name: 'description',
displayName: 'Subject',
name: 'subject',
type: 'string',
default: '',
description: 'A text description of the case. Limit: 32 KB.',
},
{
displayName: 'Is Escalated',
name: 'isEscalated',
type: 'boolean',
default: false,
description: 'Indicates whether the case has been escalated (true) or not.',
description: 'The subject of the case. Limit: 255 characters.',
},
{
displayName: 'Supplied Name',
name: 'suppliedName',
displayName: 'Supplied Company',
name: 'suppliedCompany',
type: 'string',
default: '',
description: `The name that was entered when the case was created. This field can't be updated after the case has been created`,
description: `The company name that was entered when the case was created. This field can't be updated after the case has been created..`,
},
{
displayName: 'Supplied Email',
Expand All @@ -374,6 +436,13 @@ export const caseFields = [
default: '',
description: `The email address that was entered when the case was created. This field can't be updated after the case has been created.`,
},
{
displayName: 'Supplied Name',
name: 'suppliedName',
type: 'string',
default: '',
description: `The name that was entered when the case was created. This field can't be updated after the case has been created`,
},
{
displayName: 'Supplied Phone',
name: 'suppliedPhone',
Expand All @@ -382,11 +451,14 @@ export const caseFields = [
description: `The phone number that was entered when the case was created. This field can't be updated after the case has been created.`,
},
{
displayName: 'Supplied Company',
name: 'suppliedCompany',
type: 'string',
displayName: 'Type',
name: 'type',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCaseTypes',
},
default: '',
description: `The company name that was entered when the case was created. This field can't be updated after the case has been created..`,
description: 'The type of case',
},
],
},
Expand Down
18 changes: 18 additions & 0 deletions packages/nodes-base/nodes/Salesforce/Salesforce.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,15 @@ export class Salesforce implements INodeType {
if (additionalFields.suppliedCompany !== undefined) {
body.SuppliedCompany = additionalFields.suppliedCompany as string;
}
if (additionalFields.customFieldsUi) {
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
if (customFields) {
for (const customField of customFields) {
//@ts-ignore
body[customField.fieldId] = customField.value;
}
}
}
responseData = await salesforceApiRequest.call(this, 'POST', '/sobjects/case', body);
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Case/patch-case-id
Expand Down Expand Up @@ -2034,6 +2043,15 @@ export class Salesforce implements INodeType {
if (updateFields.suppliedCompany !== undefined) {
body.SuppliedCompany = updateFields.suppliedCompany as string;
}
if (updateFields.customFieldsUi) {
const customFields = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
if (customFields) {
for (const customField of customFields) {
//@ts-ignore
body[customField.fieldId] = customField.value;
}
}
}
responseData = await salesforceApiRequest.call(this, 'PATCH', `/sobjects/case/${caseId}`, body);
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Case/get-case-id
Expand Down

0 comments on commit 9271e73

Please sign in to comment.