Skip to content

Commit b1cf281

Browse files
verhovskyGTFalcao
andauthored
ServiceNow - actions to create tickets (#18694)
* ServiceNow - actions to create tickets * Unused constant * MCP annotations * Address review --------- Co-authored-by: Guilherme Falcão <[email protected]>
1 parent a75bf0c commit b1cf281

File tree

6 files changed

+421
-12
lines changed

6 files changed

+421
-12
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import servicenow from "../../servicenow.app.mjs";
2+
3+
export default {
4+
key: "servicenow-create-case",
5+
name: "Create Case",
6+
description: "Creates a new case record in ServiceNow. [See the docs here](https://www.servicenow.com/docs/bundle/zurich-api-reference/page/integrate/inbound-rest/concept/trouble-ticket-open-api.html#title_trouble-ticket-POST-ticket-tt).",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
servicenow,
16+
name: {
17+
propDefinition: [
18+
servicenow,
19+
"name",
20+
],
21+
},
22+
description: {
23+
propDefinition: [
24+
servicenow,
25+
"description",
26+
],
27+
},
28+
severity: {
29+
propDefinition: [
30+
servicenow,
31+
"caseSeverity",
32+
],
33+
},
34+
status: {
35+
propDefinition: [
36+
servicenow,
37+
"status",
38+
],
39+
},
40+
channelName: {
41+
propDefinition: [
42+
servicenow,
43+
"channelName",
44+
],
45+
},
46+
accountId: {
47+
propDefinition: [
48+
servicenow,
49+
"accountId",
50+
],
51+
},
52+
contactId: {
53+
propDefinition: [
54+
servicenow,
55+
"contactId",
56+
],
57+
},
58+
workNote: {
59+
propDefinition: [
60+
servicenow,
61+
"workNote",
62+
],
63+
},
64+
comment: {
65+
propDefinition: [
66+
servicenow,
67+
"comment",
68+
],
69+
},
70+
},
71+
async run({ $ }) {
72+
const {
73+
name,
74+
description,
75+
severity,
76+
status,
77+
channelName,
78+
accountId,
79+
contactId,
80+
workNote,
81+
comment,
82+
} = this;
83+
84+
const channel = this.servicenow.buildChannel(channelName);
85+
86+
const notes = this.servicenow.buildNotes({
87+
workNote,
88+
comment,
89+
});
90+
91+
const relatedParties = this.servicenow.buildRelatedParties({
92+
customer: accountId,
93+
customer_contact: contactId,
94+
});
95+
96+
const response = await this.servicenow.createTroubleTicket({
97+
$,
98+
data: {
99+
ticketType: "Case",
100+
name,
101+
description,
102+
severity,
103+
status,
104+
channel,
105+
notes,
106+
relatedParties,
107+
},
108+
});
109+
110+
$.export("$summary", "Successfully created a case.");
111+
112+
return response;
113+
},
114+
};
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import servicenow from "../../servicenow.app.mjs";
2+
3+
export default {
4+
key: "servicenow-create-incident",
5+
name: "Create Incident",
6+
description: "Creates a new incident record in ServiceNow. [See the docs here](https://www.servicenow.com/docs/bundle/zurich-api-reference/page/integrate/inbound-rest/concept/trouble-ticket-open-api.html#title_trouble-ticket-POST-ticket-tt).",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
servicenow,
16+
name: {
17+
propDefinition: [
18+
servicenow,
19+
"name",
20+
],
21+
},
22+
description: {
23+
propDefinition: [
24+
servicenow,
25+
"description",
26+
],
27+
},
28+
severity: {
29+
propDefinition: [
30+
servicenow,
31+
"incidentSeverity",
32+
],
33+
},
34+
status: {
35+
propDefinition: [
36+
servicenow,
37+
"status",
38+
],
39+
},
40+
contactMethod: {
41+
propDefinition: [
42+
servicenow,
43+
"contactMethod",
44+
],
45+
},
46+
companyId: {
47+
propDefinition: [
48+
servicenow,
49+
"companyId",
50+
],
51+
},
52+
userId: {
53+
propDefinition: [
54+
servicenow,
55+
"userId",
56+
],
57+
},
58+
workNote: {
59+
propDefinition: [
60+
servicenow,
61+
"workNote",
62+
],
63+
},
64+
comment: {
65+
propDefinition: [
66+
servicenow,
67+
"comment",
68+
],
69+
},
70+
},
71+
async run({ $ }) {
72+
const {
73+
name,
74+
description,
75+
severity,
76+
status,
77+
contactMethod,
78+
companyId,
79+
userId,
80+
workNote,
81+
comment,
82+
} = this;
83+
84+
const channel = this.servicenow.buildChannel(contactMethod);
85+
86+
const relatedParties = this.servicenow.buildRelatedParties({
87+
customer: companyId,
88+
customer_contact: userId,
89+
});
90+
91+
const notes = this.servicenow.buildNotes({
92+
workNote,
93+
comment,
94+
});
95+
96+
const response = await this.servicenow.createTroubleTicket({
97+
$,
98+
data: {
99+
ticketType: "Incident",
100+
name,
101+
description,
102+
severity,
103+
status,
104+
channel,
105+
notes,
106+
relatedParties,
107+
},
108+
});
109+
110+
$.export("$summary", "Successfully created an incident.");
111+
112+
return response;
113+
},
114+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const DEFAULT_SEVERITY_OPTIONS = [
2+
{
3+
label: "Critical",
4+
value: "1",
5+
},
6+
{
7+
label: "High",
8+
value: "2",
9+
},
10+
{
11+
label: "Moderate",
12+
value: "3",
13+
},
14+
{
15+
label: "Low",
16+
value: "4",
17+
},
18+
];
19+
20+
const INCIDENT_SEVERITY_OPTIONS = [
21+
...DEFAULT_SEVERITY_OPTIONS,
22+
{
23+
label: "Planning",
24+
value: "5",
25+
},
26+
];
27+
28+
export default {
29+
DEFAULT_SEVERITY_OPTIONS,
30+
INCIDENT_SEVERITY_OPTIONS,
31+
};

components/servicenow/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/servicenow",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "Pipedream servicenow Components",
55
"main": "servicenow.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.0"
16+
"@pipedream/platform": "^3.1.0"
1717
}
1818
}

0 commit comments

Comments
 (0)