Sagar Pagar
Tera Patron

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

 

Regards,

Sagar Pagar

 

Comments
Sowmya Paladugu
Tera Explorer

@Sagar Pagar - Any automated way to identify if a custom system property is used in multiple places. So that it can be verified if  change of system property for a particular use case will effect other script. I have tried code search in studio but the user criteria records were not shown even if the system property was used in one of the record.

Sagar Pagar
Tera Patron

Hi @Sowmya Paladugu,

 

You need to search in each table like Business rules, Script includes, scheduled jobs, reports, user criteria. .... and so on.

 

Thanks,

Sagar Pagar

Sowmya Paladugu
Tera Explorer

That would be a manual search and need to identify all the scripts [server, client] and check if system property is being used.
Isn't there another way to check this.

Patrick71
Tera Contributor

@Sowmya Paladugu You can do a code search in Studio. Open studio, click "Search", then "Code Search" in the dropdown. Type in the property name, toggle on "Search in all applications", and you should be good to go.

Community Alums
Not applicable

@Sagar Pagar can you please also help me understand as how a newly created property comes in effect. How does SN platform knows as what behavior change this property brings to the system.

 

in your case; property team.development.code.reviewers  does what and how does system brings this in action? I am scratching my head on this since last couple of days. If you or someone can help me with this please.

Sagar Pagar
Tera Patron

Hi @Community Alums,

 

System properties stores the configuration information that rarely/ never changes. Once we create a system property. We need to call it explicitly in script as below mentioned.

 

gs.getProperty('<add.property.name.here>');

 

Thanks,

Sagar Pagar

Community Alums
Not applicable

@Sagar Pagar that I understood. But I want to understand that how does a new property like you explained in your post gets into action. How it is determined that how it will change the behavior.

shub606
Tera Explorer

Hi @Sagar Pagar  i want to call my System property (assignment.json.object) in UI Action button so that when user clicked on button some fields of incident form will update when incident Number matched what we get in JSON from system properties.

i created system property which have value as Array of Objects.

name - assignment.json.object
value - 
[{
"incNumber":"INC0011094",
"status":"success",
"short_description":"reset the password",
"assignment_group":"Service Group"
},
{
"incNumber":"INC12341",
"status":"failure",
"short_description":"this service not available"
},
{
"incNumber":"INC0011146",
"status":"success",
"short_description":"install the postman software",
"assignment_group":"Software"
}]


For Refrence - i am able to achieve this by created Script Include and onLoad client script but dont able to do by UI Action button Kindly help me.

My Script Include - 

var taskScripting = Class.create();
taskScripting.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getJsonObject: function() {
        var answer = gs.getProperty('assignment.json.object');
        gs.log("the system propert response: "+ answer);
        var jsonObject = JSON.parse(answer);
 
        return answer;

    },
    type: 'taskScripting'
});

My Client Script  - 

function onLoad() {
var ga = new GlideAjax('taskScripting');
ga.addParam('sysparm_name', 'getJsonObject');
ga.getXML(getDateTime);

function getDateTime(response) {
var answerXml = response.responseXML.documentElement.getAttribute("answer");
var jsonObject = JSON.parse(answerXml);
var currentIncidentNumber = g_form.getValue('number');

for (var i = 0; i < jsonObject.length; i++) {
if (jsonObject[i].incNumber === currentIncidentNumber || jsonObject[i].status === "success") {
g_form.addInfoMessage("Given ticket Number is: " + jsonObject[i].incNumber + " and Opened Ticket No is: " + currentIncidentNumber + " Matched Successfully & Status is success.");
g_form.addInfoMessage("The defined Short Description to set is: " + jsonObject[i].short_description);
g_form.addInfoMessage("The defined Assignment Group Name to set is: " + jsonObject[i].assignment_group);
g_form.setValue('short_description', jsonObject[i].short_description);
g_form.setValue('description', jsonObject[i].assignment_group);
g_form.setValue('assignment_group', jsonObject[i].assignment_group);
break; // Exit loop after finding a match
}
}
}
}

Note - kindly also reply some questions- 
1. how can we call script include in UI Action
2. how can we call System property in UI Action button




Jorn van Beek
Tera Guru

Ui actions are unique within ServiceNow as they can run server and client side. The gs.getProperty() function is only available server side.

 

so to answer your questions:

1.  a: if you run your UI Action server side, you can call script includes

     b: if you run your UI Action client side, you can use GlideAjax to call the script include (if client callable)

2.  a: if you run your UI Action server side, then yes you can use the gs.getProperty()

     b: if you run your UI Action client side, then use GlideAjax and a script include method to get it.

see, docs or developer site for more information

 

 

bast_sol
Tera Explorer

Hi,
is it possible to use it in sys_data_source's fields?

Best regard

Bastien

Version history
Last update:
‎05-28-2022 04:29 AM
Updated by: