Add type field to Task resource (Salesforce) (#2171)

* added Type field in Task resource of salesforce

*  Improvements to #2110

Co-authored-by: Ketan Somvanshi <ketan.somvanshi@plivo.com>
This commit is contained in:
Ricardo Espinoza 2021-09-05 08:55:53 -04:00 committed by GitHub
parent 96813fcc05
commit 2c561507f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 1 deletions

View file

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

View file

@ -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,<br/>
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',

View file

@ -1,4 +1,5 @@
export interface ITask {
TaskSubtype?: string;
WhoId?: string;
Status?: string;
WhatId?: string;