In servicenow, we use a reference asset field on ritm form and same through dot walk on…
- User
In servicenow, we use a reference asset field on ritm form and same through dot walk on task form. I want that when catalog task is created then make the asset field mandatory
- Assistant
In ServiceNow, to make the asset field mandatory on a catalog task when it is created, you can use a Catalog Task Business Rule or Script Include to dynamically enforce the requirement. Here’s a step-by-step guide on how to achieve this:
Step 1: Create a Catalog Task Business Rule
-
Navigate to Business Rules:
- Go to
All>System Definition>Business Rules.
- Go to
-
Create a New Business Rule:
- Click on the
Newbutton to create a new Business Rule.
- Click on the
-
Configure the Business Rule:
- Name: Provide a meaningful name, e.g., "Make Asset Field Mandatory on Catalog Task".
- Table: Choose
sc_task(Catalog Task). - Active: Ensure it is checked.
- Advanced: Ensure it is checked to allow scripting.
-
When to Run:
- When: Select
before(to run before the record is inserted into the database). - Insert: Ensure this checkbox is selected.
- When: Select
-
Condition: Specify the condition to check if it's the relevant catalog task where the asset field needs to be mandatory. This might depend on certain criteria like the type of catalog item the task belongs to.
- Example:
current.your_reference_field_here != ''; // Replace with your actual reference field
- Example:
-
Script: Write the script to check if the asset field is empty and prevent the insertion if it is.
(function executeRule(current, previous /*null when async*/) { // Dot-walk to the asset field from the catalog request item var assetField = current.variables['asset_reference_field']; // Replace 'asset_reference_field' with your actual variable name if (!assetField) { gs.addErrorMessage('The asset field is mandatory.'); current.setAbortAction(true); // Prevent the record from being inserted } })(current, previous);- Note: The script assumes you are using variables in the Catalog Item. Replace
'asset_reference_field'with the actual field name used in your Catalog Item.
Step 2: Update the Catalog Item Script (if necessary)
If necessary, ensure that the Catalog Item or corresponding client scripts and UI policies also handle the asset field correctly.
Step 3: Test Your Configuration
- Test the creation of a catalog request that generates a catalog task.
- Verify that the Catalog Task’s asset field is appropriately enforced and cannot be submitted without a value.
Important Considerations
- Client-Side Validation: Ensure that any client-side validation (i.e., UI Policies, Client Scripts) also reflects the necessity of the asset field to improve user experience before the server-side check.
- Error Handling: Ensure users are provided with clear instructions if their input is being rejected due to the asset field not being filled in.
By following these steps, you can enforce the asset field as mandatory on Catalog Tasks created in ServiceNow using server-side scripting through Business Rules.
-