Skip to content

Commit 0e77b60

Browse files
author
niuweili
committed
Merge branch 'f-servicenow' into test
2 parents aa36c13 + 258c427 commit 0e77b60

2 files changed

Lines changed: 315 additions & 309 deletions

File tree

flashduty/en/1. On-call/8. Integrations/8.5 Webhooks/8.5.5 ServiceNow sync.md

Lines changed: 157 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ Through ServiceNow sync webhook, Flashduty incidents are associated and synchron
2020
<img alt="drawing" width="600" src="https://download.flashcat.cloud/flashduty/doc/snow/snow-1.png" />
2121

2222
### Configure User
23+
2324
The user used to access ServiceNow needs to have administrator roles.
25+
2426
1. On the user list page, find the newly created `flashduty` user and go to the configuration page.
2527
2. In the edit page, click `Set Password` to set a password.
2628
3. Click `Roles` to add **admin and itil** roles.
2729
4. Click `Update` to update the configuration.
2830

2931
<img alt="drawing" width="600" src="https://download.flashcat.cloud/flashduty/doc/snow/snow-2.png" />
3032

31-
32-
3333
## In Flashduty
3434

3535
### Configure Integration
@@ -39,13 +39,13 @@ Enter the username/password and instance name configured above into the integrat
3939
- **Integration Name:** Define a name for the current integration.
4040
- **Management Team:** When a management team is selected, only team members and tenant administrators can edit this integration.
4141
- **Channel:** Select the channel where this integration takes effect.
42-
- **Sync Direction:**
43-
- To_ServiceNow: Sync Flashduty incidents to ServiceNow.
44-
- From_ServiceNow: Sync ServiceNow Incidents to Flashduty.
45-
- Two-way: Bidirectional sync between Flashduty and ServiceNow.
42+
- **Sync Direction:**
43+
- To_ServiceNow: Sync Flashduty incidents to ServiceNow.
44+
- From_ServiceNow: Sync ServiceNow Incidents to Flashduty.
45+
- Two-way: Bidirectional sync between Flashduty and ServiceNow.
4646
- **Trigger Mode**:
47-
- Auto Trigger: Requires configuration of corresponding conditions, Flashduty will automatically sync incidents that meet the conditions to ServiceNow.
48-
- Manual Trigger: Requires manual triggering of ServiceNow sync in the More Actions section of the incident details page (the integration configuration name is the trigger name).
47+
- Auto Trigger: Requires configuration of corresponding conditions, Flashduty will automatically sync incidents that meet the conditions to ServiceNow.
48+
- Manual Trigger: Requires manual triggering of ServiceNow sync in the More Actions section of the incident details page (the integration configuration name is the trigger name).
4949
- **Severity Mapping:** ServiceNow's Priority is determined by the combined values of Impact and Urgency, so you can refer to ServiceNow's `Priority Lookup Rules` for configuration. Additionally, note that only when ServiceNow Incident's Urgency changes will it trigger updates to Flashduty incident severity.
5050
- **Custom Field Mapping:** You can choose to sync certain labels or all labels of incidents as well as custom field content to ServiceNow fields (only text-type fields are supported).
5151

@@ -66,20 +66,19 @@ This method relies on ServiceNow's UI Action and Script Include configuration. T
6666
5. Enter **onClick();** in `Onclick`.
6767
6. Enter the following in `Script`:
6868

69-
```
70-
function onClick() {
71-
g_form.save();
72-
73-
var ga = new GlideAjax('IncidentWebhookHelperAjax');
74-
ga.addParam('sysparm_name', 'sendWebhook');
75-
ga.addParam('sysparm_sys_id', g_form.getUniqueValue());
76-
77-
ga.getXMLAnswer(function(response) {
78-
alert('Webhook Triggered: ' + response);
79-
});
80-
}
69+
```js
70+
function onClick() {
71+
g_form.save();
8172

82-
```
73+
var ga = new GlideAjax("IncidentWebhookHelperAjax");
74+
ga.addParam("sysparm_name", "sendWebhook");
75+
ga.addParam("sysparm_sys_id", g_form.getUniqueValue());
76+
77+
ga.getXMLAnswer(function (response) {
78+
alert("Webhook Triggered: " + response);
79+
});
80+
}
81+
```
8382

8483
7. Submit and save.
8584

@@ -96,53 +95,54 @@ This method relies on ServiceNow's UI Action and Script Include configuration. T
9695
Note: The body configures default receiving fields. If you have custom fields that need to be synced to Flashduty, you need to manually add content to the body. For example, if you want to add a field named: test_001 (this field name can be obtained when adding custom fields in the integration configuration, do not use the field name displayed in the ServiceNow Incident form), then you need to add to the body: test_001: current.getDisplayValue("test_001").
9796

9897
</div>
99-
```
100-
var IncidentWebhookHelper = Class.create();
101-
IncidentWebhookHelper.prototype = {
102-
initialize: function() {},
103-
104-
sendIncidentWebhook: function(current) {
105-
function getLastComment(sysId) {
106-
var journalGR = new GlideRecord('sys_journal_field');
107-
journalGR.addQuery('element_id', sysId);
108-
journalGR.addQuery('element', 'comments');
109-
journalGR.orderByDesc('sys_created_on');
110-
journalGR.setLimit(1);
111-
journalGR.query();
112-
if (journalGR.next()) {
113-
return journalGR.getValue('value');
114-
}
115-
return '';
116-
}
117-
118-
var body = {
119-
action_type: current.isNewRecord() ? 'insert' : 'update',
120-
number: current.getValue("number"),
121-
sys_id: current.getUniqueValue(),
122-
short_description: current.getValue("short_description"),
123-
description: current.getValue("description"),
124-
state: current.getDisplayValue("state"),
125-
impact: current.getDisplayValue("impact"),
126-
urgency: current.getDisplayValue("urgency"),
127-
comments: getLastComment(current.getUniqueValue())
128-
};
129-
130-
try {
131-
var request = new sn_ws.RESTMessageV2();
132-
request.setHttpMethod("POST");
133-
request.setEndpoint("PUSH URL");
134-
request.setRequestHeader("Content-Type", "application/json");
135-
request.setRequestBody(JSON.stringify(body));
136-
request.executeAsync();
137-
} catch (ex) {
138-
gs.error("Webhook Call failed: " + ex.message);
139-
}
140-
},
141-
142-
type: 'IncidentWebhookHelper'
98+
99+
```js
100+
var IncidentWebhookHelper = Class.create();
101+
IncidentWebhookHelper.prototype = {
102+
initialize: function () {},
103+
104+
sendIncidentWebhook: function (current) {
105+
function getLastComment(sysId) {
106+
var journalGR = new GlideRecord("sys_journal_field");
107+
journalGR.addQuery("element_id", sysId);
108+
journalGR.addQuery("element", "comments");
109+
journalGR.orderByDesc("sys_created_on");
110+
journalGR.setLimit(1);
111+
journalGR.query();
112+
if (journalGR.next()) {
113+
return journalGR.getValue("value");
114+
}
115+
return "";
116+
}
117+
118+
var body = {
119+
action_type: current.isNewRecord() ? "insert" : "update",
120+
number: current.getValue("number"),
121+
sys_id: current.getUniqueValue(),
122+
short_description: current.getValue("short_description"),
123+
description: current.getValue("description"),
124+
state: current.getDisplayValue("state"),
125+
impact: current.getDisplayValue("impact"),
126+
urgency: current.getDisplayValue("urgency"),
127+
comments: getLastComment(current.getUniqueValue()),
128+
<label name='field_mapping' tab='10'>{original.key}: current.getDisplayValue("{original.key}")</label>
143129
};
144130

145-
```
131+
try {
132+
var request = new sn_ws.RESTMessageV2();
133+
request.setHttpMethod("POST");
134+
request.setEndpoint("PUSH URL");
135+
request.setRequestHeader("Content-Type", "application/json");
136+
request.setRequestBody(JSON.stringify(body));
137+
request.executeAsync();
138+
} catch (ex) {
139+
gs.error("Webhook Call failed: " + ex.message);
140+
}
141+
},
142+
143+
type: "IncidentWebhookHelper",
144+
};
145+
```
146146

147147
6. Submit and save.
148148
7. Return to the Script Includes list and continue creating.
@@ -151,25 +151,29 @@ Note: The body configures default receiving fields. If you have custom fields th
151151
10. Keep `Client callable` and `Active` checked.
152152
11. Enter the following content in `Script`:
153153

154-
```
154+
```js
155155
var IncidentWebhookHelperAjax = Class.create();
156-
IncidentWebhookHelperAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
157-
sendWebhook: function() {
158-
var sysId = this.getParameter('sysparm_sys_id');
159-
var gr = new GlideRecord('incident');
160-
if (gr.get(sysId)) {
161-
var helper = new IncidentWebhookHelper();
156+
IncidentWebhookHelperAjax.prototype = Object.extendsObject(
157+
global.AbstractAjaxProcessor,
158+
{
159+
sendWebhook: function () {
160+
var sysId = this.getParameter("sysparm_sys_id");
161+
var gr = new GlideRecord("incident");
162+
if (gr.get(sysId)) {
163+
var helper = new IncidentWebhookHelper();
162164
helper.sendIncidentWebhook(gr);
163-
return 'Success';
164-
}
165-
return 'Request failed';
166-
}
167-
});
165+
return "Success";
166+
}
167+
return "Request failed";
168+
},
169+
}
170+
);
168171
```
169-
172+
170173
12. Submit and save.
171174

172175
### Auto Sync
176+
173177
This method relies on ServiceNow's Business Rules configuration. Using this method, you can automatically sync Incidents to Flashduty when there are new or update events.
174178
175179
#### Configure Business Rules
@@ -187,92 +191,92 @@ Note: The body configures default receiving fields. If you have custom fields th
187191
188192
</div>
189193
190-
```
191-
(function executeRule(current, previous) {
192-
function getLastComment(recordSysId) {
193-
var journalGR = new GlideRecord('sys_journal_field');
194-
journalGR.addQuery('element_id', recordSysId);
195-
journalGR.addQuery('element', 'comments');
196-
journalGR.orderByDesc('sys_created_on');
197-
journalGR.setLimit(1);
198-
journalGR.query();
199-
if (journalGR.next()) {
200-
var comment = journalGR.getValue('value');
201-
return comment;
202-
}
203-
204-
return '';
205-
}
206-
207-
var operation = current.operation() || 'unknown';
208-
var isPreviousNull = previous === null;
209-
var createdOn = current.getValue('sys_created_on');
210-
var updatedOn = current.getValue('sys_updated_on');
211-
var isNewRecord = createdOn === updatedOn;
212-
213-
var action = 'update';
214-
if (isPreviousNull && isNewRecord) {
215-
action = 'insert';
216-
}
217-
218-
var body = {
219-
action_type: action,
220-
number: current.getValue("number"),
221-
sys_id: current.getUniqueValue(),
222-
short_description: current.getValue("short_description"),
223-
description: current.getValue("description"),
224-
state: current.getDisplayValue("state"),
225-
impact: current.getDisplayValue("impact"),
226-
urgency: current.getDisplayValue("urgency"),
227-
comments: getLastComment(current.getUniqueValue())
228-
};
229-
230-
try {
231-
var endpoint = '';
232-
var request = new sn_ws.RESTMessageV2();
233-
request.setHttpMethod("POST");
234-
request.setEndpoint(endpoint);
235-
request.setRequestHeader("Content-Type", "application/json");
236-
request.setRequestBody(JSON.stringify(body));
237-
request.executeAsync();
238-
} catch (ex) {
239-
gs.error("Error sending webhook: " + ex.message);
240-
}
194+
```js
195+
(function executeRule(current, previous) {
196+
function getLastComment(recordSysId) {
197+
var journalGR = new GlideRecord("sys_journal_field");
198+
journalGR.addQuery("element_id", recordSysId);
199+
journalGR.addQuery("element", "comments");
200+
journalGR.orderByDesc("sys_created_on");
201+
journalGR.setLimit(1);
202+
journalGR.query();
203+
if (journalGR.next()) {
204+
var comment = journalGR.getValue("value");
205+
return comment;
206+
}
241207
208+
return "";
209+
}
210+
211+
var operation = current.operation() || "unknown";
212+
var isPreviousNull = previous === null;
213+
var createdOn = current.getValue("sys_created_on");
214+
var updatedOn = current.getValue("sys_updated_on");
215+
var isNewRecord = createdOn === updatedOn;
216+
217+
var action = "update";
218+
if (isPreviousNull && isNewRecord) {
219+
action = "insert";
220+
}
221+
222+
var body = {
223+
action_type: action,
224+
number: current.getValue("number"),
225+
sys_id: current.getUniqueValue(),
226+
short_description: current.getValue("short_description"),
227+
description: current.getValue("description"),
228+
state: current.getDisplayValue("state"),
229+
impact: current.getDisplayValue("impact"),
230+
urgency: current.getDisplayValue("urgency"),
231+
comments: getLastComment(current.getUniqueValue()),
232+
};
233+
234+
try {
235+
var endpoint = "";
236+
var request = new sn_ws.RESTMessageV2();
237+
request.setHttpMethod("POST");
238+
request.setEndpoint(endpoint);
239+
request.setRequestHeader("Content-Type", "application/json");
240+
request.setRequestBody(JSON.stringify(body));
241+
request.executeAsync();
242+
} catch (ex) {
243+
gs.error("Error sending webhook: " + ex.message);
244+
}
242245
})(current, previous);
246+
```
243247
244-
```
245248
7. Submit and save.
246249
247250
## Sync Information
248251
249252
### Form Fields
250-
| ServiceNow | Flashduty | Notes |
251-
| ---------- | -------- | ---- |
252-
| Short_description | Title | |
253-
| Description | Description | |
254-
| Additional comments | Comments | |
255-
| State | Progress | |
256-
| Urgency | Severity | |
257-
| Others | Custom Fields | |
258253
259-
### Status Mapping
254+
| ServiceNow | Flashduty | Notes |
255+
| ------------------- | ------------- | ----- |
256+
| Short_description | Title | |
257+
| Description | Description | |
258+
| Additional comments | Comments | |
259+
| State | Progress | |
260+
| Urgency | Severity | |
261+
| Others | Custom Fields | |
260262
261-
| ServiceNow | Flashduty | Notes |
262-
| ---------- | -------- | ---- |
263-
| New | Trigger | |
264-
| In Progress | Processing | |
265-
| On Hold | Snoozed | Default snooze 2 hours |
266-
| Resolved | CLosed | |
267-
| Closed | CLosed | |
268-
| Canceled | CLosed | |
263+
### Status Mapping
269264
265+
| ServiceNow | Flashduty | Notes |
266+
| ----------- | ---------- | ---------------------- |
267+
| New | Trigger | |
268+
| In Progress | Processing | |
269+
| On Hold | Snoozed | Default snooze 2 hours |
270+
| Resolved | CLosed | |
271+
| Closed | CLosed | |
272+
| Canceled | CLosed | |
270273
271274
### Priority Mapping
275+
272276
Only when ServiceNow's Urgency value changes will it affect Flashduty's Severity
273277
274-
| ServiceNow | Flashduty | Notes |
275-
| ---------- | -------- | ---- |
276-
| Low | Info | |
277-
| Medium | Warning | |
278-
| High | Critical | |
278+
| ServiceNow | Flashduty | Notes |
279+
| ---------- | --------- | ----- |
280+
| Low | Info | |
281+
| Medium | Warning | |
282+
| High | Critical | |

0 commit comments

Comments
 (0)