To achieve this, you will need to implement the following:
- Set the Application field in the Incident with the Resource string field from the Alert Table when the Incident Reference is set on the Alert Table.
This can be accomplished using Business Rules on the Alert Table and possibly on the Incident Table.
Here's a step-by-step solution to achieve the desired functionality:
Step 1: Create Business Rule on Alert Table
-
Navigate to System Definition > Business Rules.
-
Create a New Business Rule:
- Name:
Set Application on Incident
- Table:
Alert
- When:
After Insert or Update (depending on your requirements)
- Condition:
current.incident.changes() && current.resource (if the incident is updated and resource is populated)
-
Add the following script in the Script field:
(function executeRule(current, previous /*null when async*/) {
// Ensure the Incident reference and Resource string are populated
if (current.incident && current.resource) {
// Create a GlideRecord object for the Incident table
var incidentRecord = new GlideRecord('incident');
// Query the referenced Incident record using the sys_id
if (incidentRecord.get(current.incident.sys_id)) {
// Set the Application field to the value of Resource field from the Alert
incidentRecord.application = current.resource;
// Update the Incident record
incidentRecord.update();
}
}
})(current, previous);
Step 2: Open the Incident
If you intend to automatically open the Incident form after it is updated, you can use client-side scripting or UI Actions.
Step 3: Ensure Incident Application Field Accepts String Values
Ensure that the application field in the Incident table can accept the value you are trying to set from the resource field.
Additional Consideration: Ensure Data Integrity and Handling Edge Cases
- Ensure the Application field does accept the Resource field value. The relationship or data type must match.
- Add error-handling mechanisms if necessary, such as logging or conditional validation to ensure smooth execution.
This Business Rule will trigger whenever the Incident reference or Resource field is updated on the Alert table and will copy the Resource field value into the Application field of the referenced Incident.
Confirm and Test
- Create or update a record in the Alert table to ensure the Business Rule is triggered.
- Verify that the Incident record is updated with the Application field set to the value of the Resource field from the Alert.
By following these steps, you'll be able to dynamically update the Incident's Application field based on the Resource value from the Alert table, ensuring data consistency across your ServiceNow application.