ServiceNow Business Rule
Need to install in the ServiceNow integration?
Setting Up ServiceNow Business Rules for FireHydrant Integration
Business rules in ServiceNow automate actions based on database operations (create, update, delete). In this case, we're using business rules to automatically sync ServiceNow incidents with FireHydrant, which:
- Eliminates manual double-entry of incident data
- Ensures your incidents in FireHydrant stay in sync with ServiceNow
- Allows teams to work in their preferred tool while maintaining data consistency
- Automates communication between systems based on specific conditions you define
Create two separate business rules to handle incident creation and updates independently.
Note:
While both rules use the same script, separating them allows for different trigger conditions and better control over when incidents are created versus updated in FireHydrant.
Business Rule 1: Create FireHydrant Incident
- Navigate to System Definition > Business Rules
- Click "New" to create a business rule
- Configure the following settings:
- Name: FireHydrant Create Incident
- Table: Incident [incident] (or custom table)
- Active: ✓
- When to run: After
- Insert: ✓
- Update: ✗
- Delete: ✗
- Query: ✗
- Set Filter Conditions (Optional)
- Add specific conditions for incident creation
- Example: Priority is Critical, or Category equals Production Issue
Business Rule 2: Update FireHydrant Incident
- Create another business rule with these settings:
- Name: FireHydrant Update Incident
- Table: Incident [incident] (or custom table)
- Active: ✓
- When to run: After
- Insert: ✗
- Update: ✓
- Delete: ✗
- Query: ✗
- Set Filter Conditions (Optional)
- Add conditions for when updates should sync
- Example: Status changes or Priority updates
Script
(function executeRule(current, previous) {
var fireHydrantPrefix = "FireHydrant - ";
var fhWebhookUrl = 'Enter the webhook URL from your FireHydrant ServiceNow integration settings';
// FH Required fields Do Not Remove!!
var requiredFields = ['sys_id', 'number', 'state'];
// All the fields you want to map withing FH
var syncedFields = ['short_description', 'category', 'subcategory', 'business_service','impact','urgency', 'caller', 'description'];
var allFields = requiredFields.concat(syncedFields);
allFields.sort();
gs.info(fireHydrantPrefix + "Fields to update: {0}", allFields.join(", "));
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(fhWebhookUrl);
request.setHttpMethod('POST');
var requestBody = {};
allFields.forEach(function (field) {
requestBody[field] = current.getValue(field);
});
// FH Required fields Do Not Remove!!
requestBody['sn_user'] = gs.getUserName();
requestBody['sn_user_email'] = gs.getUser().getEmail();
requestBody['sn_table'] = current.getTableName();
requestBody['fh_type'] = 'ticket';
request.setRequestHeader('Accept', 'application/json');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestBody(JSON.stringify(requestBody));
gs.info(fireHydrantPrefix + "Request body: {0}", JSON.stringify(requestBody));
var response = request.execute();
if (response.getStatusCode() !== 200) {
gs.info(fireHydrantPrefix + "Bad request: {0}", response.getBody());
}
})(current, previous);
Configuration Variables
- fhWebhookUrl: Enter the webhook URL from your FireHydrant ServiceNow integration settings
- syncedFields: List the ServiceNow ticket fields you want to sync with FireHydrant. Modify this array to match your field mapping configuration
Note:
Ensure your field names in
syncedFields
match those configured in your FireHydrant field mapping settings.
Work Note Business Rule
When managing incidents across ServiceNow and FireHydrant, keeping communication in sync between platforms is crucial for effective incident response. By setting up a business rule to sync ServiceNow work notes to FireHydrant, you ensure that all team updates, progress notes, and important communications are automatically shared between systems. This eliminates the need for manual copy-pasting, reduces the risk of missed updates, and allows team members to collaborate effectively regardless of which platform they're using. Support teams can continue working in ServiceNow while incident responders track progress in FireHydrant, maintaining a single source of truth for incident communications.
- Navigate to System Definition > Business Rules
- Click "New" to create a business rule
- Configure the following settings:
- Name: FireHydrant - Work Notes
- Table: Journal Entry [sys_journal_field]
- Active: ✓
- When to run: After
- Insert: ✓
- Update: ✗
- Delete: ✗
- Query: ✗
- Set Filter Conditions
- Add specific conditions for work note syncing
- Element is work_notes is Critical
- Name is incident
Script
(function executeRule(current, previous /*null when async*/ ) {
try {
var fireHydrantPrefix = "FireHydrant WorkNotes - ";
var fhWebhookUrl = 'Enter the webhook URL from your FireHydrant ServiceNow integration settings';
// Prepare the payload
var payload = {
fh_type: "generic_chat_message",
sn_user: gs.getUser().getEmail(),
parent_sys_id: current.getValue("element_id"),
value: current.getValue("value"),
table: current.getValue("name")
};
// Prepare request
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(fhWebhookUrl);
request.setHttpMethod('POST');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestBody(JSON.stringify(payload));
var response = request.execute();
gs.info(fireHydrantPrefix + "Request sent, status code: " + response.getStatusCode());
if (response.getStatusCode() !== 200) {
gs.info(fireHydrantPrefix + "Bad request: {0}", response.getBody());
}
} catch (ex) {
gs.error('Error in Work Note Notification Business Rule: ' + ex.message);
}
})(current, previous);
Updated 7 days ago