Skip to content

Commit 4f3ad75

Browse files
authored
Noah drew patch 1 (#1959)
* Check if Fiscal Year is safe for Deletion You can do a lot of damage related to data corruption and impacted financials if you delete your Fiscal Periods/Fiscal Year when it's already in use with live data like Cost Plans and Benefit Plans. This will validate a single Fiscal Year to validate it's not used yet and safe for deletion if your Fiscal Periods have Validation issues. Use this in the [System Definition > Scripts - Background] module. Enter in the Fiscal Year by display name on line 2. * Delete Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion * Create Check if Fiscal Year is safe for deletion * Create README.md
1 parent 50c00cc commit 4f3ad75

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-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+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
You can do a lot of damage related to data corruption and impacted financials if you delete your Fiscal Periods/Fiscal Year when it's already in use with live data like Cost Plans and Benefit Plans.
2+
3+
This will validate a single Fiscal Year to validate it's not used yet and safe for deletion if your Fiscal Periods have Validation issues.
4+
5+
Use this in the [System Definition > Scripts - Background] module. Enter in the Fiscal Year by display name on line 2.

0 commit comments

Comments
 (0)