System Properties & it's Usage in ServiceNow

 

System Properties

System properties used to store configuration information that rarely or never changes. We can add or update to control the system behavior. It is best practice to use a system property instead of hard cladding the fixed values.System properties store configuration information that rarely or never changes.

System properties are maintained in the System properties [sys_properties] table in ServiceNow.

 

Available Fields

For System property we have these fields.

  • Name: Add a unique name for a system property. Generally to add or maintain system property we should maintain the naming conventions. Example: Let's take example, we have to create a property for Team Development Code Reviewers assignment group, so name will be team.development.code.reviewers 
  • Description: Type a brief description for the property. What is the purpose/function and where will it be used?
  • Type: We have multiple data types for a property. For example- Integer, String, Choice list,color, Time format,  Timezone, Password, Password2, Date format, true/false,  Image, Uploaded image, Short string etc.
  • Value: We have to specify the desired values for property. It may be sys_id, true/false, color list etc.
  • Ignore cache: When we change a system property value, the system always flushes the cache for the sys_properties table. This option is used to determine whether to flush this property's value from all other server-side caches.
  • Private: This option is used to set this property to true to exclude this property from being imported via update sets. Keeping system properties private prevents settings in one instance from overwriting values in another instance. For example, you may not want a system property in a development instance to use the same value as a production instance.
  • Read roles: This option is used to define the roles that have read access to this property.
  • Write roles: This option is used to define the roles that have write access to this property. 

    Procedure to create System Property

    Navigate to application navigator and search System properties or sys_propertie.list Click a New button to add a new property.

    Example:

    Let's create a system property for the Change Advisory Board.

     

    Name: change.advisory.board

    Description: Change Advisory Board assignment group sys_id, used in server scripts.

    Type: String

    Value: d75bcbe4873f4110ec2363150cbb35e6

     

    Fill out this information and click the Save button.

    find_real_file.png

     

    Using System Properties on Server side script.

    The system property can be used at any server side script like Business rules, Scheduled jobs, UI action, Script Include etc.

     

    var property_value = gs.getProperty(‘property_name’);

     

    In our case, it will be

     

    var change_cab = gs.getProperty(‘change.advisory.board’); 
    

     

    Using System Properties on Client side

    As per my understanding, we can use 

    1) Display business rule with g_scratchpad variable

    2) GlideAjax with client callable Script include


    Let's take the example of making the required fields read-only for closed change requests.  

    We need to enter the required fields in system property, separated by commas, which will be read only by closed change requests.

     

    Name: change.request.closed.read.only.fields

    Value: short_description,description,priority,assignment_group,assigned_to,….

     

    1) Display Business rule with g_scratchpad variable

    We can get the property value in Display business rules as follows.

     

    g_scratchpad.read_only_fields = gs.getProperty(‘change.request.closed.read.only.fields’);

    Use g_scratchpad variable in on-load client script

    var readOnlyFields = g_scratchpad.read_only_fields;
    
    var fieldsArray = readOnlyFields.split(',');
    
    for (var i=0; i < fieldsArray.length; i++) {
          g_form.setReadOnly(fieldsArray[i], true);
    }      
    

     

    2) GlideAjax with client callable Script include

    We can get the property value in Script Include as follows.

    var GetReadOnlyFields= Class.create();
    GetReadOnlyFields.prototype = Object.extendsObject(AbstractAjaxProcessor, {
        
         getReadOnlyFields: function() {
         var answer = gs.getProperty(‘change.request.closed.read.only.fields’);
         return answer;
    }

     

    Use get the property value from answer variable in on-load client script.

    var glideAjax = new GlideAjax(‘GetReadOnlyFields’);
    glideAjax.addParam('sysparm_name',’getReadOnlyFields’);
    glideAjax.getXML(getFieldsCallback); 
    
    function getFieldsCallback(response) { 
            var answer = response.responseXML.documentElement.getAttribute('answer');
            alert(answer);
    
            var readOnlyFields = answer;
    
            var fieldsArray = readOnlyFields.split(',');
    
            for (var i=0; i < fieldsArray.length; i++) {
                 g_form.setReadOnly(fieldsArray[i], true);
            }      
    }
    
    

     

    Some Useful Links

    Available System Properties - San Diego

    Working with System Properties

    System Properties - ServiceNow Elite

    Best Practices – System Properties

     

    Thanks,

    Sagar Pagar

Comments

Popular posts from this blog

Script Action and Example

#BuildWithCreatorStudio Challenge