Skip to content

Commit 1543625

Browse files
committed
fix tickets again
1 parent 38f0e79 commit 1543625

2 files changed

Lines changed: 40 additions & 41 deletions

File tree

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
// Process NinjaOne ticketing board data
22
const items = (data && data.data && Array.isArray(data.data)) ? data.data : (Array.isArray(data) ? data : []);
33

4-
// Apply SquaredUp timeframe client-side: the trigger/board endpoint has no
5-
// documented date-filter syntax, so filter raw Unix-second values here before
6-
// they get converted to ISO strings below.
7-
const startTime = parseInt('{{timeframe.unixStart}}', 10);
8-
const endTime = parseInt('{{timeframe.unixEnd}}', 10);
9-
const hasTimeframe = Number.isFinite(startTime) && Number.isFinite(endTime);
10-
11-
const pickTimestamp = (item) => {
12-
const candidates = [item.updatedAt, item.lastActivityAt, item.createdAt];
13-
for (const v of candidates) {
14-
if (typeof v === 'number' && v > 1000000000 && v < 10000000000) return v;
15-
}
16-
return null;
17-
};
18-
19-
const filtered = hasTimeframe
20-
? items.filter((item) => {
21-
const ts = pickTimestamp(item);
22-
return ts !== null && ts >= startTime && ts <= endTime;
23-
})
24-
: items;
4+
// SquaredUp timeframe (Unix seconds). If substitution doesn't happen the
5+
// parseInt yields NaN and hasTimeframe is false — filter is skipped and all
6+
// rows pass through.
7+
const startTime = parseInt('{{timeframe.unixStart}}');
8+
const endTime = parseInt('{{timeframe.unixEnd}}');
9+
const hasTimeframe = !isNaN(startTime) && !isNaN(endTime);
2510

2611
/**
2712
* Recursively converts NinjaOne Unix timestamps (seconds) to ISO strings.
@@ -47,20 +32,33 @@ const convertTimestamps = (obj) => {
4732
return obj;
4833
};
4934

50-
result = filtered.map(item => {
51-
const converted = convertTimestamps(item);
52-
53-
return {
54-
...converted,
55-
// Normalize IDs as strings for SquaredUp correlation
56-
id: converted.id ? converted.id.toString() : null,
57-
organizationId: (converted.organizationId || converted.clientId) ? (converted.organizationId || converted.clientId).toString() : null,
58-
deviceId: (converted.deviceId || converted.nodeId) ? (converted.deviceId || converted.nodeId).toString() : null,
59-
boardId: converted.boardId ? converted.boardId.toString() : null,
60-
requesterId: converted.requesterId ? converted.requesterId.toString() : null,
61-
assigneeId: (converted.assigneeId || converted.assignedAppUserId) ? (converted.assigneeId || converted.assignedAppUserId).toString() : null,
62-
ticketFormId: converted.ticketFormId ? converted.ticketFormId.toString() : null,
63-
// Ensure tags are a comma-separated string if they are an array
64-
tags: Array.isArray(converted.tags) ? converted.tags.join(', ') : converted.tags
65-
};
66-
});
35+
result = items
36+
.filter((item) => {
37+
if (!hasTimeframe) return true;
38+
const raw = (typeof item.updatedAt === 'number' && item.updatedAt > 1e9) ? item.updatedAt
39+
: (typeof item.lastActivityAt === 'number' && item.lastActivityAt > 1e9) ? item.lastActivityAt
40+
: (typeof item.createdAt === 'number' && item.createdAt > 1e9) ? item.createdAt
41+
: (typeof item.updateTime === 'number' && item.updateTime > 1e9) ? item.updateTime
42+
: (typeof item.createTime === 'number' && item.createTime > 1e9) ? item.createTime
43+
: null;
44+
if (raw === null) return false;
45+
const tsSec = raw > 1e12 ? Math.floor(raw / 1000) : raw;
46+
return tsSec >= startTime && tsSec <= endTime;
47+
})
48+
.map(item => {
49+
const converted = convertTimestamps(item);
50+
51+
return {
52+
...converted,
53+
// Normalize IDs as strings for SquaredUp correlation
54+
id: converted.id ? converted.id.toString() : null,
55+
organizationId: (converted.organizationId || converted.clientId) ? (converted.organizationId || converted.clientId).toString() : null,
56+
deviceId: (converted.deviceId || converted.nodeId) ? (converted.deviceId || converted.nodeId).toString() : null,
57+
boardId: converted.boardId ? converted.boardId.toString() : null,
58+
requesterId: converted.requesterId ? converted.requesterId.toString() : null,
59+
assigneeId: (converted.assigneeId || converted.assignedAppUserId) ? (converted.assigneeId || converted.assignedAppUserId).toString() : null,
60+
ticketFormId: converted.ticketFormId ? converted.ticketFormId.toString() : null,
61+
// Ensure tags are a comma-separated string if they are an array
62+
tags: Array.isArray(converted.tags) ? converted.tags.join(', ') : converted.tags
63+
};
64+
});

plugins/NinjaOne/v1/dataStreams/tickets.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "tickets",
33
"displayName": "Tickets",
44
"tags": ["Ticketing"],
5-
"description": "Tickets from one or more ticket boards",
6-
"baseDataSourceName": "httpRequestScopedSingle",
5+
"description": "Tickets from a specific board (single board selection only)",
6+
"baseDataSourceName": "httpRequestScoped",
77
"config": {
88
"httpMethod": "post",
99
"paging": {
@@ -23,13 +23,14 @@
2323
}
2424
},
2525
"expandInnerObjects": true,
26-
"endpointPath": "/v2/ticketing/trigger/board/{{object.boardId}}/run",
26+
"endpointPath": "/v2/ticketing/trigger/board/{{objects[0].boardId}}/run",
2727
"postRequestScript": "tickets.js",
2828
"pathToData": "data",
2929
"getArgs": [],
3030
"headers": [],
3131
"postBody": {}
3232
},
33+
"objectLimit": 1,
3334
"matches": {
3435
"sourceType": {
3536
"type": "oneOf",

0 commit comments

Comments
 (0)