Skip to content

Commit a58e065

Browse files
committed
Adding optional note creation to ticket
1 parent 25589c0 commit a58e065

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

components/connectwise_psa/actions/create-ticket/create-ticket.mjs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "connectwise_psa-create-ticket",
55
name: "Create Ticket",
66
description: "Creates a new ticket in Connectwise. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Tickets/postServiceTickets)",
7-
version: "0.0.1",
7+
version: "0.1.0",
88
type: "action",
99
props: {
1010
connectwise,
@@ -31,6 +31,23 @@ export default {
3131
"priority",
3232
],
3333
},
34+
note: {
35+
type: "string[]",
36+
label: "Note(s)",
37+
description: "Text content of one or more notes to add to the ticket",
38+
optional: true,
39+
},
40+
},
41+
methods: {
42+
createTicketNote({
43+
id, ...args
44+
}) {
45+
return this.connectwise._makeRequest({
46+
method: "POST",
47+
path: `/service/tickets/${id}/notes`,
48+
...args,
49+
});
50+
},
3451
},
3552
async run({ $ }) {
3653
const response = await this.connectwise.createTicket({
@@ -52,7 +69,38 @@ export default {
5269
: undefined,
5370
},
5471
});
55-
$.export("$summary", `Successfully created ticket with ID: ${response.id}`);
56-
return response;
72+
const { id } = response;
73+
const { note } = this;
74+
const createdNotes = [];
75+
if (id && note?.length) {
76+
const notes = Array.isArray(note)
77+
? note
78+
: [
79+
note,
80+
];
81+
for (let note of notes) {
82+
const response = await this.createTicketNote({
83+
$,
84+
id,
85+
data: {
86+
text: note,
87+
detailDescriptionFlag: true,
88+
},
89+
});
90+
createdNotes.push(response);
91+
}
92+
}
93+
const amountNotes = createdNotes.length;
94+
$.export("$summary", `Successfully created ticket (ID: ${id})${amountNotes
95+
? ` and added ${amountNotes} notes`
96+
: ""}`);
97+
return {
98+
...(amountNotes
99+
? {
100+
createdNotes,
101+
}
102+
: undefined),
103+
...response,
104+
};
57105
},
58106
};

0 commit comments

Comments
 (0)