How can I make Risk Assessment question answers read only?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2025 10:47 PM
I have a Survey assessment which opens up in a UI page in native view, and a widget in Service Portal. I need to make few answers of certain questions as read only, as we are auto populating answers with a Business Rule. Please let me know how we can achieve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2025 11:23 PM
To make certain survey answers read-only in both the UI page and Service Portal in ServiceNow, you can follow these steps:
- UI Page (Native View):
- Client Script: Create a client script to set the fields as read-only. You can use the g_form.setReadOnly method to achieve this. For example:
function onLoad() {
g_form.setReadOnly('question_field_name', true);
}
- UI Policy: Alternatively, you can create a UI Policy to make fields read-only based on certain conditions.
- Service Portal (Widget):
- Widget Client Script: Modify the widget's client script to set the fields as read-only. You can use AngularJS or the ServiceNow API to achieve this. For example:
$scope.data.question_field_name = true;
// Assuming you have a data object that holds the field properties
- Widget Server Script: Ensure the server script populates the data object correctly and sets the read-only property.
- Business Rule: Since you are auto-populating answers with a Business Rule, ensure that the Business Rule sets a flag or property that the client script or widget can check to make the fields read-only.
- Assessment Metric: If you are using assessment metrics, you can set the read-only property directly in the assessment metric definition.
Here is a more detailed example for the Service Portal widget:
Client Script:
function($scope, spUtil) {
$scope.data.question_field_name = true; // Set read-only property
}
Server Script:
(function() {
data.question_field_name = true; // Ensure the field is read-only
})();
By combining these approaches, you can ensure that the survey answers are read-only in both the native UI page and the Service Portal widget.
If you need further assistance or have more questions, feel free to ask!