Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

System property

pratyusha11
Tera Contributor

Configure the values below in json format in a system property

1 ACCEPTED SOLUTION


The JSON structure is designed to be easily parsable by a script that would calculate the risk.

  • criticalServicesZero: This array groups all the rules for when the script identifies zero critical services at Depth 1/2.

  • criticalServicesOneOrMore: This array groups all the rules for when the script identifies one or more critical services at Depth 1/2.

  • infrastructureCIOnly: This object handles the specific edge case where the record has an infrastructure CI but no related impacted services, assigning a fixed risk score.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@pratyusha11 

but what to put in property ? what mapping?

Example: consider I want to map assignment group with location so in system property I will store like this

Then I can easily get the location associated to that group using this background script

Something similar you can also do

[
  {
    "group": "acme",
    "location": "India"
  },
  {
    "group": "support desk",
    "location": "Australia"
  }
]

Script:

// JSON object as a string (usually stored in a property)
var groupLocationJson = [
  {
    "group": "acme",
    "location": "India"
  },
  {
    "group": "support desk",
    "location": "Australia"
  }
];

// ---- FUNCTION TO GET LOCATION BY GROUP NAME ----
function getLocationByGroup(groupName) {
    for (var i = 0; i < groupLocationJson.length; i++) {
        if (groupLocationJson[i].group.toLowerCase() === groupName.toLowerCase()) {
            return groupLocationJson[i].location;
        }
    }
    return null; // not found
}

// ---- EXAMPLE USAGE ----
var groupName = "support desk"; // Replace with input as needed
var location = getLocationByGroup(groupName);

gs.info('Group: ' + groupName + ', Location: ' + location);

Output:

AnkurBawiskar_0-1754403047011.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Viraj Hudlikar
Tera Sage
Tera Sage

Hello @pratyusha11 

 

Your system property will be as per below screenshot:

VirajHudlikar_0-1754403251858.png

 

Your value of property will be as showcased below.

{
  "criticalServicesZero": [
    {"totalCIs": "1-4", "risk": 200},
    {"totalCIs": "5-9", "risk": 200},
    {"totalCIs": "10-30", "risk": 300},
    {"totalCIs": "31-100", "risk": 400},
    {"totalCIs": "101+", "risk": 500}
  ],
  "criticalServicesOneOrMore": [
    {"totalCIs": "1-4", "risk": 500},
    {"totalCIs": "5-9", "risk": 1000},
    {"totalCIs": "10-30", "risk": 1000},
    {"totalCIs": "31-100", "risk": 1000},
    {"totalCIs": "101+", "risk": 1000}
  ],
  "infrastructureCIOnly": {
    "risk": 1000
  }
}

 

Now when we try to use this property in background script with below code you can use value from it.

var gr_prop_JSON_value = gs.getProperty('property_test');

var riskConfig = JSON.parse(gr_prop_JSON_value);

// Now you can access the data, for example:
var riskValue = riskConfig.criticalServicesZero[0].risk; 
gs.print(riskValue); // this will give output as 200.

var totalCIs = riskConfig.criticalServicesZero[0].totalCIs; 
gs.print(totalCIs ); // this will give output as 1-4.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

How to configure 'depth' here ?


The JSON structure is designed to be easily parsable by a script that would calculate the risk.

  • criticalServicesZero: This array groups all the rules for when the script identifies zero critical services at Depth 1/2.

  • criticalServicesOneOrMore: This array groups all the rules for when the script identifies one or more critical services at Depth 1/2.

  • infrastructureCIOnly: This object handles the specific edge case where the record has an infrastructure CI but no related impacted services, assigning a fixed risk score.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.