From 1392894361b5f4c6af0084d83224bb8de06bd890 Mon Sep 17 00:00:00 2001 From: Noah-Drew Date: Wed, 8 Oct 2025 18:16:05 -0400 Subject: [PATCH 1/4] 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. --- .../Check if Fiscal Year is safe for deletion | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion diff --git a/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion b/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion new file mode 100644 index 0000000000..f376961ec5 --- /dev/null +++ b/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion @@ -0,0 +1,47 @@ +// Enter in the display name of the Fiscal Year such as "FY26" or "FY32" to validate. +var fiscalYear = "FY24"; + +var fiscalGr = new GlideRecord("fiscal_period") +fiscalGr.addEncodedQuery("name=" + fiscalYear); +fiscalGr.query(); + +if (fiscalGr.next()) { + + var fyId = fiscalGr.getUniqueValue(); + var isValidDeletion = true; + var tableDetections = []; + + var grDictionary = new GlideRecord("sys_dictionary"); + grDictionary.addEncodedQuery("reference=fiscal_period"); + grDictionary.query(); + while(grDictionary.next()) { + + if (grDictionary.getValue("name") == "fiscal_period") + continue; + + var tableGr = new GlideRecord(grDictionary.getValue("name")); + tableGr.addEncodedQuery(grDictionary.getValue("element") + ".fiscal_year=" + fyId); + tableGr.setLimit(1); + tableGr.query(); + if (tableGr.next()) { + isValidDeletion = false; + if (tableDetections.indexOf(grDictionary.getValue("name")) == -1) { + tableDetections.push(grDictionary.getValue("name")); + } + } + + } + + if (isValidDeletion) { + gs.info("No Fiscal Period data found for this year."); + gs.info("High chance it should be safe unless data exists and is blocked from a query BR or other access controls."); + gs.info("Confirm with customer before proceeding with any deletions for testing."); + } else { + gs.info("DO NOT DELETE FISCAL PERIODS FOR " + fiscalYear + "!"); + gs.info("Deletion will cause broken references and corruption."); + gs.info("Fiscal data is used in the following tables: " + tableDetections.join(" | ")); + } + +} else { + gs.info("Fiscal Period does not exist, make sure the Name entered is a valid Fiscal Period") +} From 739847c944e264f8400f2f562e978730003deca5 Mon Sep 17 00:00:00 2001 From: Noah-Drew Date: Wed, 8 Oct 2025 18:37:35 -0400 Subject: [PATCH 2/4] Delete Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion --- .../Check if Fiscal Year is safe for deletion | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion diff --git a/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion b/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion deleted file mode 100644 index f376961ec5..0000000000 --- a/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion +++ /dev/null @@ -1,47 +0,0 @@ -// Enter in the display name of the Fiscal Year such as "FY26" or "FY32" to validate. -var fiscalYear = "FY24"; - -var fiscalGr = new GlideRecord("fiscal_period") -fiscalGr.addEncodedQuery("name=" + fiscalYear); -fiscalGr.query(); - -if (fiscalGr.next()) { - - var fyId = fiscalGr.getUniqueValue(); - var isValidDeletion = true; - var tableDetections = []; - - var grDictionary = new GlideRecord("sys_dictionary"); - grDictionary.addEncodedQuery("reference=fiscal_period"); - grDictionary.query(); - while(grDictionary.next()) { - - if (grDictionary.getValue("name") == "fiscal_period") - continue; - - var tableGr = new GlideRecord(grDictionary.getValue("name")); - tableGr.addEncodedQuery(grDictionary.getValue("element") + ".fiscal_year=" + fyId); - tableGr.setLimit(1); - tableGr.query(); - if (tableGr.next()) { - isValidDeletion = false; - if (tableDetections.indexOf(grDictionary.getValue("name")) == -1) { - tableDetections.push(grDictionary.getValue("name")); - } - } - - } - - if (isValidDeletion) { - gs.info("No Fiscal Period data found for this year."); - gs.info("High chance it should be safe unless data exists and is blocked from a query BR or other access controls."); - gs.info("Confirm with customer before proceeding with any deletions for testing."); - } else { - gs.info("DO NOT DELETE FISCAL PERIODS FOR " + fiscalYear + "!"); - gs.info("Deletion will cause broken references and corruption."); - gs.info("Fiscal data is used in the following tables: " + tableDetections.join(" | ")); - } - -} else { - gs.info("Fiscal Period does not exist, make sure the Name entered is a valid Fiscal Period") -} From d59e554e2e8b92e9c5686c8852ded4af8b8002d1 Mon Sep 17 00:00:00 2001 From: Noah-Drew Date: Wed, 8 Oct 2025 18:38:57 -0400 Subject: [PATCH 3/4] Create Check if Fiscal Year is safe for deletion --- .../Check if Fiscal Year is safe for deletion | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion/Check if Fiscal Year is safe for deletion diff --git a/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion/Check if Fiscal Year is safe for deletion b/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion/Check if Fiscal Year is safe for deletion new file mode 100644 index 0000000000..f376961ec5 --- /dev/null +++ b/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion/Check if Fiscal Year is safe for deletion @@ -0,0 +1,47 @@ +// Enter in the display name of the Fiscal Year such as "FY26" or "FY32" to validate. +var fiscalYear = "FY24"; + +var fiscalGr = new GlideRecord("fiscal_period") +fiscalGr.addEncodedQuery("name=" + fiscalYear); +fiscalGr.query(); + +if (fiscalGr.next()) { + + var fyId = fiscalGr.getUniqueValue(); + var isValidDeletion = true; + var tableDetections = []; + + var grDictionary = new GlideRecord("sys_dictionary"); + grDictionary.addEncodedQuery("reference=fiscal_period"); + grDictionary.query(); + while(grDictionary.next()) { + + if (grDictionary.getValue("name") == "fiscal_period") + continue; + + var tableGr = new GlideRecord(grDictionary.getValue("name")); + tableGr.addEncodedQuery(grDictionary.getValue("element") + ".fiscal_year=" + fyId); + tableGr.setLimit(1); + tableGr.query(); + if (tableGr.next()) { + isValidDeletion = false; + if (tableDetections.indexOf(grDictionary.getValue("name")) == -1) { + tableDetections.push(grDictionary.getValue("name")); + } + } + + } + + if (isValidDeletion) { + gs.info("No Fiscal Period data found for this year."); + gs.info("High chance it should be safe unless data exists and is blocked from a query BR or other access controls."); + gs.info("Confirm with customer before proceeding with any deletions for testing."); + } else { + gs.info("DO NOT DELETE FISCAL PERIODS FOR " + fiscalYear + "!"); + gs.info("Deletion will cause broken references and corruption."); + gs.info("Fiscal data is used in the following tables: " + tableDetections.join(" | ")); + } + +} else { + gs.info("Fiscal Period does not exist, make sure the Name entered is a valid Fiscal Period") +} From ce3696ad2e1417499ddc5fd8f8f8d2e49adedb58 Mon Sep 17 00:00:00 2001 From: Noah-Drew Date: Wed, 8 Oct 2025 18:40:04 -0400 Subject: [PATCH 4/4] Create README.md --- .../Check if Fiscal Year is safe for deletion/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion/README.md diff --git a/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion/README.md b/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion/README.md new file mode 100644 index 0000000000..70a522b71b --- /dev/null +++ b/Specialized Areas/Fix scripts/Check if Fiscal Year is safe for deletion/README.md @@ -0,0 +1,5 @@ +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.