Check for existence of system property

Abhijit Das7
Tera Expert

Hi everyone, 

 

I have created around 6-7 custom system properties according to my business requirement. Now I am creating one Scripted rest api and I have to check whether these properties exist or not in this system. 

 

How can check whether the system properties exist or not with Scripted rest api.

 

cc; @Ankur Bawiskar 

 

Thanks in advance. 

1 ACCEPTED SOLUTION

Hello @Abhijit Das7,

 

Thanks for clarifying your query. I was under the impression that if any of the property is present, then the expected output needs to be true.

 

Now that your requirement is to have output as true when all 6 property exists, then you can consider using condition gr.getRowCount() == 6

 

var propertiesArray = ["propertyName1", "propertyName2", "propertyName3", "propertyName4", "propertyName5", "propertyName6" ]

var gr = new GlideRecord("sys_properties");
gr.addQuery("name", "IN", propertiesArray);
gr.query();
var result = gr.getRowCount() == 6;
gs.info("testing sys property" + result);

 

Please mark this response as correct and/or helpful if it assisted you with your question 😊

 

Regards,

Aman Kumar 

View solution in original post

7 REPLIES 7

Gangadhar Ravi
Giga Sage
Giga Sage

@Abhijit Das7 

To check if a property exists in ServiceNow using the REST API, you can use the following endpoint: "https://<your_instance>.service-now.com/api/now/table/sys_properties?sysparm_query=name=<property_name>"; where <your_instance> is your ServiceNow instance name and <property_name> is the name of the property you want to check

 

Please mark my answer correct and helpful if this works for you.

Hi @Gangadhar Ravi 

 

My requirement is something like this that inside Scripted REST API (POST), I have to check whether these 6 properties exist using GlideRecord query or not. And if these exist then I will update these properties and if they doesn't exist then I have to return error message. 

 

Thanks in advance

Hi @Abhijit Das7 

 

Use the below code to check presence of any system property.

 

//This below code will update the given property value

 

var grSysProp = new GlideRecord("sys_properties");
grSysProp.addQuery("name", <property_name>); // change the correct propert name
grSysProp.query();
if(grSysProp.next()){
      grSysProp.value= "NewValue"; // update the new value here
      grSysProp.update();
} else {
      var erroMsg = "Property not exist";
}
// you can return the errorMsg variable in return response of REST Call

 

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Ankur Bawiskar
Tera Patron
Tera Patron

@Abhijit Das7 

what's the business requirement for this?

what did you try so far and what didn't work?

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