Sure, I can help you configure your business rule in ServiceNow to update the manager field in the alm_hardware table based on a specific catalog variable value. Here's a step-by-step guide:
-
Navigate to the Business Rules Module
- Go to
System Definition > Business Rules.
-
Create a New Business Rule
- Click on the
New button to create a new business rule.
-
Set Basic Business Rule Information
- Name: Give your business rule a meaningful name, e.g., "Update Asset Manager Field".
- Table: Set this to
sc_req_item since your RITM records are created in this table.
- Advanced: Ensure the "Advanced" checkbox is checked to allow for more complex scripting.
-
Set Conditions
- In the "When to run" section, you can specify the conditions under which this business rule should run.
- Typically, you might set it to run "after" the update, especially if updates to the asset record (
alm_hardware) depend on the current state of the RITM.
-
Script Tab
- Here’s where the script that performs the required action belongs. You need to check the value of the
reason catalog variable and then update the manager field in alm_hardware.
Here's an example script to get you started:
(function executeRule(current, previous /*null when async*/) {
// Get catalog variables
var grItem = new GlideRecord('sc_item_option_mtom');
grItem.addQuery('request_item', current.sys_id);
grItem.addQuery('sc_item_option.value', 'vendor'); // Adjust the field as appropriate
grItem.query();
if (grItem.next()) {
// Check if the current RITM has an asset associated with it
var assetGr = new GlideRecord('alm_hardware');
assetGr.get('asset_tag', current.variables.asset_tag); // Adjust the field mapping as needed
if (assetGr.isValidRecord()) {
// Update the manager field
assetGr.manager = current.variables.assigned_to.manager; // Ensure your field mappings are correct
assetGr.update();
}
}
})(current, previous);
-
Note on Field Mappings
- Make sure that the field names in the script correctly reflect the fields in your instance. You may need to adjust
current.variables.assigned_to.manager to the correct catalog variable names.
-
Save and Test
- Save your business rule.
- Test the business rule by creating a catalog request and selecting "vendor" as the reason. Ensure that the
manager field in the corresponding alm_hardware record gets updated as expected.
Tips:
- Debugging: Use
gs.info() statements in your script to log variable values and flow checkpoints for easier debugging.
- Permissions: Ensure the user executing the business rule has the necessary permissions to read and write to both
sc_req_item and alm_hardware tables.
- ServiceNow Best Practices: Avoid hardcoding field values and table names. Use service catalog variables and dynamic queries wherever possible.
Hopefully, this helps you set up your business rule. Let me know if you have further questions!