Skip to content

Commit d59e554

Browse files
authored
Create Check if Fiscal Year is safe for deletion
1 parent 739847c commit d59e554

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Enter in the display name of the Fiscal Year such as "FY26" or "FY32" to validate.
2+
var fiscalYear = "FY24";
3+
4+
var fiscalGr = new GlideRecord("fiscal_period")
5+
fiscalGr.addEncodedQuery("name=" + fiscalYear);
6+
fiscalGr.query();
7+
8+
if (fiscalGr.next()) {
9+
10+
var fyId = fiscalGr.getUniqueValue();
11+
var isValidDeletion = true;
12+
var tableDetections = [];
13+
14+
var grDictionary = new GlideRecord("sys_dictionary");
15+
grDictionary.addEncodedQuery("reference=fiscal_period");
16+
grDictionary.query();
17+
while(grDictionary.next()) {
18+
19+
if (grDictionary.getValue("name") == "fiscal_period")
20+
continue;
21+
22+
var tableGr = new GlideRecord(grDictionary.getValue("name"));
23+
tableGr.addEncodedQuery(grDictionary.getValue("element") + ".fiscal_year=" + fyId);
24+
tableGr.setLimit(1);
25+
tableGr.query();
26+
if (tableGr.next()) {
27+
isValidDeletion = false;
28+
if (tableDetections.indexOf(grDictionary.getValue("name")) == -1) {
29+
tableDetections.push(grDictionary.getValue("name"));
30+
}
31+
}
32+
33+
}
34+
35+
if (isValidDeletion) {
36+
gs.info("No Fiscal Period data found for this year.");
37+
gs.info("High chance it should be safe unless data exists and is blocked from a query BR or other access controls.");
38+
gs.info("Confirm with customer before proceeding with any deletions for testing.");
39+
} else {
40+
gs.info("DO NOT DELETE FISCAL PERIODS FOR " + fiscalYear + "!");
41+
gs.info("Deletion will cause broken references and corruption.");
42+
gs.info("Fiscal data is used in the following tables: " + tableDetections.join(" | "));
43+
}
44+
45+
} else {
46+
gs.info("Fiscal Period does not exist, make sure the Name entered is a valid Fiscal Period")
47+
}

0 commit comments

Comments
 (0)