- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 01:26 PM - edited 11-10-2024 06:45 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 12:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 01:33 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 06:19 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 06:51 PM - edited 11-10-2024 06:53 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 07:18 PM
what's the business requirement for this?
what did you try so far and what didn't work?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader