@trg-admin/n8n-nodes-zoho-desk 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,6 +14,7 @@ import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescrip
|
|
|
14
14
|
* API answer. Upgrade to GET /layouts/{layoutId}/fields/{fieldId}/dependentValues if users
|
|
15
15
|
* hit rejections in tenants that do enforce the mapping.
|
|
16
16
|
*/
|
|
17
|
+
export declare function readDepartmentScope(context: ILoadOptionsFunctions): string;
|
|
17
18
|
export declare function loadTaxonomyOptions(context: ILoadOptionsFunctions, apiName: string): Promise<Array<{
|
|
18
19
|
name: string;
|
|
19
20
|
value: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZohoDesk = void 0;
|
|
4
|
+
exports.readDepartmentScope = readDepartmentScope;
|
|
4
5
|
exports.loadTaxonomyOptions = loadTaxonomyOptions;
|
|
5
6
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
6
7
|
const GenericFunctions_1 = require("./GenericFunctions");
|
|
@@ -29,12 +30,39 @@ function cleanCommaSeparated(value) {
|
|
|
29
30
|
* API answer. Upgrade to GET /layouts/{layoutId}/fields/{fieldId}/dependentValues if users
|
|
30
31
|
* hit rejections in tenants that do enforce the mapping.
|
|
31
32
|
*/
|
|
33
|
+
function readDepartmentScope(context) {
|
|
34
|
+
const ctx = context;
|
|
35
|
+
// Top level: the ticket create form carries departmentId directly.
|
|
36
|
+
try {
|
|
37
|
+
const current = ctx.getCurrentNodeParameter?.('departmentId');
|
|
38
|
+
if (current !== undefined && current !== null && current !== '') {
|
|
39
|
+
return String(current).trim();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Not available in this context; fall through.
|
|
44
|
+
}
|
|
45
|
+
// Nested: on update, Department lives in the Additional Fields collection. Values inside
|
|
46
|
+
// a collection are invisible to getCurrentNodeParameter, so read the raw parameters.
|
|
47
|
+
try {
|
|
48
|
+
const nested = ctx.getCurrentNodeParameters?.()?.additionalFields
|
|
49
|
+
?.departmentId;
|
|
50
|
+
if (nested !== undefined && nested !== null && nested !== '') {
|
|
51
|
+
return String(nested).trim();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Treat as unscoped.
|
|
56
|
+
}
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
32
59
|
async function loadTaxonomyOptions(context, apiName) {
|
|
33
|
-
// Taxonomy is department-scoped
|
|
34
|
-
|
|
60
|
+
// Taxonomy is department-scoped: without a department the API returns the whole org,
|
|
61
|
+
// which offers values that the target department's layout may reject.
|
|
62
|
+
const departmentId = readDepartmentScope(context);
|
|
35
63
|
const qs = { module: 'tickets', apiNames: apiName };
|
|
36
64
|
if (departmentId) {
|
|
37
|
-
qs.departmentId =
|
|
65
|
+
qs.departmentId = departmentId;
|
|
38
66
|
}
|
|
39
67
|
try {
|
|
40
68
|
const responseData = await GenericFunctions_1.zohoDeskApiRequest.call(context, 'GET', '/organizationFields', {}, qs, 0);
|
|
@@ -236,10 +264,24 @@ class ZohoDesk {
|
|
|
236
264
|
type: 'options',
|
|
237
265
|
typeOptions: {
|
|
238
266
|
loadOptionsMethod: 'getChannels',
|
|
239
|
-
loadOptionsDependsOn: ['organizationId'],
|
|
267
|
+
loadOptionsDependsOn: ['organizationId', 'departmentId'],
|
|
240
268
|
},
|
|
241
269
|
default: 'Email',
|
|
242
|
-
description: 'Channel through which the ticket was received or created. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
|
270
|
+
description: 'Channel through which the ticket was received or created, scoped to the selected Department. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
// Create already has a top-level required Department, so only offer this
|
|
274
|
+
// here for Update - it both scopes the taxonomy values and moves the ticket.
|
|
275
|
+
displayName: 'Department',
|
|
276
|
+
name: 'departmentId',
|
|
277
|
+
type: 'options',
|
|
278
|
+
typeOptions: {
|
|
279
|
+
loadOptionsMethod: 'getDepartments',
|
|
280
|
+
loadOptionsDependsOn: ['organizationId'],
|
|
281
|
+
},
|
|
282
|
+
default: '',
|
|
283
|
+
displayOptions: { show: { resource: ['ticket'], operation: ['update'] } },
|
|
284
|
+
description: 'Department whose layout defines the values offered by the Classification, Category and Sub-Category fields below. Leave blank to list values from every department in the organization. Note: setting this also moves the ticket into that department, so set it to the ticket\'s current department unless you intend to move it.',
|
|
243
285
|
},
|
|
244
286
|
{
|
|
245
287
|
displayName: 'Classification',
|
|
@@ -920,7 +962,13 @@ class ZohoDesk {
|
|
|
920
962
|
}
|
|
921
963
|
catch {
|
|
922
964
|
try {
|
|
923
|
-
|
|
965
|
+
// Channel is department-scoped too, so honour the same scope as the taxonomy.
|
|
966
|
+
const channelQs = { module: 'tickets', apiNames: 'channel' };
|
|
967
|
+
const channelDepartmentId = readDepartmentScope(this);
|
|
968
|
+
if (channelDepartmentId) {
|
|
969
|
+
channelQs.departmentId = channelDepartmentId;
|
|
970
|
+
}
|
|
971
|
+
const fieldsResponse = await GenericFunctions_1.zohoDeskApiRequest.call(this, 'GET', '/organizationFields', {}, channelQs, 0);
|
|
924
972
|
const fields = Array.isArray(fieldsResponse.data)
|
|
925
973
|
? fieldsResponse.data
|
|
926
974
|
: Array.isArray(fieldsResponse)
|