Small improvement to Zendesk-Node

This commit is contained in:
Jan Oberhauser 2020-04-11 14:56:25 +02:00
parent e7f1fce1dd
commit 8e190d24a5
2 changed files with 78 additions and 180 deletions

View file

@ -109,6 +109,41 @@ export const ticketFields = [
},
},
options: [
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Field',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
displayName: 'Custom Field',
name: 'customFieldsValues',
values: [
{
displayName: 'ID',
name: 'id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCustomFields',
},
default: '',
description: 'Custom field ID',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Custom field Value.',
},
],
},
],
},
{
displayName: 'External ID',
name: 'externalId',
@ -206,54 +241,6 @@ export const ticketFields = [
},
],
},
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Field',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
resource: [
'ticket',
],
operation: [
'create',
],
jsonParameters: [
false,
],
},
},
default: {},
options: [
{
displayName: 'Custom Field',
name: 'customFieldsValues',
values: [
{
displayName: 'ID',
name: 'id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCustomFields',
},
default: '',
description: 'Custom field ID',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Custom field Value.',
},
],
},
],
},
{
displayName: ' Additional Fields',
name: 'additionalFieldsJson',
@ -275,30 +262,9 @@ export const ticketFields = [
],
},
},
description: `Object of values to set as described <a href="https://developer.zendesk.com/rest_api/docs/support/tickets" target="_blank">here</a>.`,
},
{
displayName: ' Custom Fields',
name: 'customFieldsJson',
type: 'json',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
displayOptions: {
show: {
resource: [
'ticket',
],
operation: [
'create',
],
jsonParameters: [
true,
],
},
},
description: `Array of customs fields <a href="https://developer.zendesk.com/rest_api/docs/support/tickets#setting-custom-field-values" target="_blank">Details</a>`,
},
/* -------------------------------------------------------------------------- */
/* ticket:update */
/* -------------------------------------------------------------------------- */
@ -357,6 +323,41 @@ export const ticketFields = [
},
},
options: [
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Field',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
displayName: 'Custom Field',
name: 'customFieldsValues',
values: [
{
displayName: 'ID',
name: 'id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCustomFields',
},
default: '',
description: 'Custom field ID',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Custom field Value.',
},
],
},
],
},
{
displayName: 'External ID',
name: 'externalId',
@ -454,54 +455,6 @@ export const ticketFields = [
},
],
},
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Field',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
resource: [
'ticket',
],
operation: [
'update',
],
jsonParameters: [
false,
],
},
},
default: {},
options: [
{
displayName: 'Custom Field',
name: 'customFieldsValues',
values: [
{
displayName: 'ID',
name: 'id',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCustomFields',
},
default: '',
description: 'Custom field ID',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Custom field Value.',
},
],
},
],
},
{
displayName: ' Update Fields',
name: 'updateFieldsJson',
@ -523,31 +476,9 @@ export const ticketFields = [
],
},
},
description: `Object of values to update as described <a href="https://developer.zendesk.com/rest_api/docs/support/tickets" target="_blank">here</a>.`,
},
{
displayName: ' Custom Fields',
name: 'customFieldsJson',
type: 'json',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
displayOptions: {
show: {
resource: [
'ticket',
],
operation: [
'update',
],
jsonParameters: [
true,
],
},
},
required: true,
description: `Array of customs fields <a href='https://developer.zendesk.com/rest_api/docs/support/tickets#setting-custom-field-values'>Details</a>`,
},
/* -------------------------------------------------------------------------- */
/* ticket:get */
/* -------------------------------------------------------------------------- */

View file

@ -167,20 +167,6 @@ export class Zendesk implements INodeType {
comment,
};
if (jsonParameters) {
const customFieldsJson = this.getNodeParameter('customFieldsJson', i) as string;
if (customFieldsJson !== '' ) {
if (validateJSON(customFieldsJson) !== undefined) {
body.custom_fields = JSON.parse(customFieldsJson);
} else {
throw new Error('Custom fields must be a valid JSON');
}
}
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
if (additionalFieldsJson !== '' ) {
@ -194,13 +180,10 @@ export class Zendesk implements INodeType {
}
}
} else {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const customFields = (this.getNodeParameter('customFieldsUi', i) as IDataObject).customFieldsValues as IDataObject[];
if (additionalFields.type) {
body.type = additionalFields.type as string;
}
@ -222,8 +205,8 @@ export class Zendesk implements INodeType {
if (additionalFields.tags) {
body.tags = additionalFields.tags as string[];
}
if (customFields) {
body.custom_fields = customFields;
if (additionalFields.customFieldsUi) {
body.custom_fields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
}
}
responseData = await zendeskApiRequest.call(this, 'POST', '/tickets', { ticket: body });
@ -236,20 +219,6 @@ export class Zendesk implements INodeType {
const body: ITicket = {};
if (jsonParameters) {
const customFieldsJson = this.getNodeParameter('customFieldsJson', i) as string;
if (customFieldsJson !== '' ) {
if (validateJSON(customFieldsJson) !== undefined) {
body.custom_fields = JSON.parse(customFieldsJson);
} else {
throw new Error('Custom fields must be a valid JSON');
}
}
const updateFieldsJson = this.getNodeParameter('updateFieldsJson', i) as string;
if (updateFieldsJson !== '' ) {
@ -267,8 +236,6 @@ export class Zendesk implements INodeType {
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
const customFields = (this.getNodeParameter('customFieldsUi', i) as IDataObject).customFieldsValues as IDataObject[];
if (updateFields.type) {
body.type = updateFields.type as string;
}
@ -290,8 +257,8 @@ export class Zendesk implements INodeType {
if (updateFields.tags) {
body.tags = updateFields.tags as string[];
}
if (customFields) {
body.custom_fields = customFields;
if (updateFields.customFieldsUi) {
body.custom_fields = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
}
}
responseData = await zendeskApiRequest.call(this, 'PUT', `/tickets/${ticketId}`, { ticket: body });