From 2c561507f799b76fb74d4b333f67ac00f5771ea2 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Sun, 5 Sep 2021 08:55:53 -0400 Subject: [PATCH] :sparkles: Add type field to Task resource (Salesforce) (#2171) * added Type field in Task resource of salesforce * :zap: Improvements to #2110 Co-authored-by: Ketan Somvanshi --- .../nodes/Salesforce/Salesforce.node.ts | 28 ++++++++++++++++++- .../nodes/Salesforce/TaskDescription.ts | 20 +++++++++++++ .../nodes/Salesforce/TaskInterface.ts | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts b/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts index 5f0060c660..88357cfcab 100644 --- a/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts +++ b/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts @@ -120,7 +120,6 @@ import { import { LoggerProxy as Logger, } from 'n8n-workflow'; -import { query } from '../Elasticsearch/descriptions/placeholders'; export class Salesforce implements INodeType { description: INodeTypeDescription = { @@ -691,6 +690,27 @@ export class Salesforce implements INodeType { sortOptions(returnData); return returnData; }, + // Get all the task types to display them to user so that he can + // select them easily + async getTaskTypes(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + // 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/task/describe'); + for (const field of fields) { + if (field.name === 'TaskSubtype') { + for (const pickValue of field.picklistValues) { + const pickValueName = pickValue.label; + const pickValueId = pickValue.value; + returnData.push({ + name: pickValueName, + value: pickValueId, + }); + } + } + } + sortOptions(returnData); + return returnData; + }, // Get all the task subjects to display them to user so that he can // select them easily async getTaskSubjects(this: ILoadOptionsFunctions): Promise { @@ -2332,6 +2352,9 @@ export class Salesforce implements INodeType { const body: ITask = { Status: status, }; + if (additionalFields.type !== undefined) { + body.TaskSubtype = additionalFields.type as string; + } if (additionalFields.whoId !== undefined) { body.WhoId = additionalFields.whoId as string; } @@ -2417,6 +2440,9 @@ export class Salesforce implements INodeType { const taskId = this.getNodeParameter('taskId', i) as string; const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; const body: ITask = {}; + if (updateFields.type !== undefined) { + body.TaskSubtype = updateFields.type as string; + } if (updateFields.whoId !== undefined) { body.WhoId = updateFields.whoId as string; } diff --git a/packages/nodes-base/nodes/Salesforce/TaskDescription.ts b/packages/nodes-base/nodes/Salesforce/TaskDescription.ts index 2cd2b3fd5b..a3d4a294e5 100644 --- a/packages/nodes-base/nodes/Salesforce/TaskDescription.ts +++ b/packages/nodes-base/nodes/Salesforce/TaskDescription.ts @@ -388,6 +388,16 @@ export const taskFields = [ }, description: 'The subject line of the task, such as “Call” or “Send Quote.” Limit: 255 characters.', }, + { + displayName: 'Type', + name: 'type', + type: 'options', + default: '', + typeOptions: { + loadOptionsMethod: 'getTaskTypes', + }, + description: `Represents Type of the task, such as Call or Meeting.`, + }, { displayName: 'What Id', name: 'whatId', @@ -750,6 +760,16 @@ export const taskFields = [ user may have deselected the reminder checkbox in the Salesforce user interface,
or the reminder has already fired at the time indicated by the value.`, }, + { + displayName: 'Type', + name: 'type', + type: 'options', + default: '', + typeOptions: { + loadOptionsMethod: 'getTaskTypes', + }, + description: `Represents Type of the task, such as Call or Meeting.`, + }, { displayName: 'What Id', name: 'whatId', diff --git a/packages/nodes-base/nodes/Salesforce/TaskInterface.ts b/packages/nodes-base/nodes/Salesforce/TaskInterface.ts index 218c905eab..a95b557a1e 100644 --- a/packages/nodes-base/nodes/Salesforce/TaskInterface.ts +++ b/packages/nodes-base/nodes/Salesforce/TaskInterface.ts @@ -1,4 +1,5 @@ export interface ITask { + TaskSubtype?: string; WhoId?: string; Status?: string; WhatId?: string;