How can I make Risk Assessment question answers read only?

Community Alums
Not applicable

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.

1 REPLY 1

naveenkaush
Tera Contributor

To make certain survey answers read-only in both the UI page and Service Portal in ServiceNow, you can follow these steps:

  1. 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.
  1. 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.
  1. 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.
  2. 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!