In ServiceNow, if you want to allow users to edit a specific field, such as "asset type," in a Requested Item (RITM) after the request has been generated, you can achieve this using a combination of Flow Designer, Business Rules, UI Policies, and Client Scripts. Here's a step-by-step approach to achieving this:
-
Flow Designer:
You stated that you have a Flow Designer Flow that submits a catalog item request and sets the variable values. Ensure your flow submits the request and generates the RITM appropriately.
-
Modify Catalog Item Form:
Ensure that the "asset type" variable is part of your catalog item. You can do this from the Maintain Items module.
-
Client Script:
Create a Client Script to enable the "asset type" field on the Requested Item (RITM) form for editing. Here’s an example script to enable the field when a specific condition is met:
- Navigate to "System Definition" -> "Client Scripts"
- Click "New" to create a new Client Script
- Fill out the form with the following details:
Name: Enable Asset Type Field
Table: sc_req_item (Requested Item)
UI Type: All (or Desktop Service Portal depending on where you want to use it)
Type: onLoad
- In the Script section, use the following code:
(function() {
// Check if the current user has the right role to edit the field
if (gs.hasRole('YOUR_ROLE_HERE') || g_user.hasRole('YOUR_ROLE_HERE')) {
// Enable the 'asset_type' field
g_form.setReadOnly('u_asset_type', false);
} else {
// Make sure it's read-only for others
g_form.setReadOnly('u_asset_type', true);
}
})();
Replace 'YOUR_ROLE_HERE' with the actual role you want to authorize for editing.
-
UI Policy:
Optionally, you can use UI Policies to control the visibility or read-only status of the "asset type" field dynamically without JavaScript. This is a more user-friendly interface to define the rules.
- Navigate to "System UI" -> "UI Policies"
- Click "New" to create a new UI Policy
- Fill out the form with the necessary details, for example:
Name: Enable Asset Type Field
Table: sc_req_item (Requested Item)
- Define the conditions under which the UI Policy should apply.
- In the "UI Policy Actions" related list, select the "asset type" field and set it to make it editable.
-
Business Rule:
If you have specific conditions for when the field should be editable (e.g., based on the RITM's state), you might need to create a Business Rule to control these conditions.
- Navigate to "System Definition" -> "Business Rules"
- Click "New" to create a new Business Rule
- Fill out the form with the necessary details, for example:
Name: Set User Editable Asset Type
Table: sc_req_item
When: before (or after as per requirements)
Insert: true
Update: true
- In the advanced section, you can add the script to set the field editable based on conditions:
(function executeRule(current, previous /*null when async*/) {
if (current.state == 'YOUR_STATE_CONDITIONS') {
current.u_asset_type.setReadOnly(false);
} else {
current.u_asset_type.setReadOnly(true);
}
})(current, previous);
Adjust 'YOUR_STATE_CONDITIONS' to match your criteria.
By following these steps, you can control the editability of the "asset type" field on the RITM form based on your requirements. The Client Script will run on the Requested Item form when it's loaded, and you can complement it with UI Policies and Business Rules for more complex conditions.