Skip to content

Commit 465b218

Browse files
committed
New sys property utils
1 parent 22fc3fa commit 465b218

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from .utils import table_api_call
2+
3+
4+
def set_sys_property(instance, property_name: str, value: str):
5+
"""
6+
Set a sys_property in the instance.
7+
8+
Parameters:
9+
-----------
10+
instance: SNowInstance
11+
The instance to set the property in
12+
property_name: str
13+
The name of the property to set
14+
value: str
15+
The value to set for the property
16+
17+
"""
18+
19+
property = table_api_call(
20+
instance=instance,
21+
table="sys_properties",
22+
params={"sysparm_query": f"name={property_name}", "sysparm_fields": "sys_id"},
23+
)["result"]
24+
25+
if not property:
26+
property_sysid = ""
27+
method = "POST"
28+
else:
29+
property_sysid = "/" + property[0]["sys_id"]
30+
method = "PUT"
31+
32+
property = table_api_call(
33+
instance=instance,
34+
table=f"sys_properties{property_sysid}",
35+
method=method,
36+
json={"name": property_name, "value": value},
37+
)
38+
39+
# Verify that the property was updated
40+
assert property["result"]["value"] == value, f"Error setting {property_name}."
41+
42+
43+
def get_sys_property(instance, property_name: str) -> str:
44+
"""
45+
Get a sys_property from the instance.
46+
47+
Parameters:
48+
-----------
49+
instance: SNowInstance
50+
The instance to get the property from
51+
property_name: str
52+
The name of the property to get
53+
54+
Returns:
55+
--------
56+
str
57+
The value of the property
58+
59+
"""
60+
property_value = table_api_call(
61+
instance=instance,
62+
table="sys_properties",
63+
params={"sysparm_query": f"name={property_name}", "sysparm_fields": "value"},
64+
)["result"][0]["value"]
65+
66+
return property_value

0 commit comments

Comments
 (0)