diff --git a/Server-Side Components/Business Rules/Currency conversion to USD/currenct_Converstion_to_USD.js b/Server-Side Components/Business Rules/Currency conversion to USD/currenct_Converstion_to_USD.js new file mode 100644 index 0000000000..0504a6ab80 --- /dev/null +++ b/Server-Side Components/Business Rules/Currency conversion to USD/currenct_Converstion_to_USD.js @@ -0,0 +1,72 @@ +(function executeRule(current, previous /*null when async*/) { + + // Extract the first 3 characters of the budget currency code (e.g., "INR", "EUR") + var currencyCode = current.budget_currency ? current.budget_currency.toString().substring(0, 3) : ''; + + // Convert the annual budget value to a float + var amount = parseFloat(current.annual_budget); + + // Validate input: If currency code is missing or amount is not a valid number, clear the USD field and exit + if (!currencyCode || isNaN(amount)) { + current.u_annual_budget_usd = ''; + return; + } + + // If the currency is already USD, no conversion needed — store the original amount + if (currencyCode === 'USD') { + current.u_annual_budget_usd = amount; + return; + } + + // Check if the currency exists in the fx_currency table + var currencyGR = new GlideRecord('fx_currency'); + currencyGR.addQuery('code', currencyCode); + currencyGR.query(); + + // If currency is not found, clear the USD field and exit + if (!currencyGR.next()) { + current.u_annual_budget_usd = ''; + return; + } + + // Get the latest exchange rate for the selected currency from fx_rate table + var fxGR = new GlideRecord('fx_rate'); + fxGR.addQuery('currency.code', currencyCode); + fxGR.orderByDesc('sys_updated_on'); // Sort by most recent update + fxGR.setLimit(1); // Limit to the latest record + fxGR.query(); + + // If no exchange rate found, clear the USD field and exit + if (!fxGR.next()) { + current.u_annual_budget_usd = ''; + return; + } + + var rate = parseFloat(fxGR.getValue('rate')); // Exchange rate for selected currency + + // Get the latest exchange rate for USD from fx_rate table + var fxGR1 = new GlideRecord('fx_rate'); + fxGR1.addQuery('currency.code', 'USD'); + fxGR1.orderByDesc('sys_updated_on'); // Sort by most recent update + fxGR1.setLimit(1); // Limit to the latest record + fxGR1.query(); + + // If no USD exchange rate found, clear the USD field and exit + if (!fxGR1.next()) { + current.u_annual_budget_usd = ''; + return; + } + + var usdRate = parseFloat(fxGR1.getValue('rate')); // USD base rate + + // Perform conversion only if both rates are valid and non-zero + if (!isNaN(rate) && !isNaN(usdRate) && rate !== 0) { + var convertedAmount = (amount / rate) * usdRate; // Convert to USD + current.u_annual_budget_usd = convertedAmount; // Store the converted value + } else { + gs.info("Invalid exchange rate values"); + current.u_annual_budget_usd = ''; + } + +})(current, previous); +`` diff --git a/Server-Side Components/Business Rules/Currency conversion to USD/readme.md b/Server-Side Components/Business Rules/Currency conversion to USD/readme.md new file mode 100644 index 0000000000..ffbcd618bb --- /dev/null +++ b/Server-Side Components/Business Rules/Currency conversion to USD/readme.md @@ -0,0 +1,12 @@ +This script is designed to automatically convert the value of the Annual Budget field (annual_budget) from its original currency to USD. It uses the fx_currency and fx_rate tables to fetch the latest exchange rates and performs the conversion only when valid data is available. +🔍 Key Features: + +Field Focus: Converts the annual_budget field based on the currency specified in budget_currency. +Validation: Ensures both the currency code and amount are valid before proceeding. +Currency Check: If the currency is already USD, it bypasses conversion. +Exchange Rate Lookup: Retrieves the most recent exchange rates for both the source currency and USD. +Conversion Logic: Applies the formula +USD Amount=(Original AmountSource Rate)×USD Rate\text{USD Amount} = \left(\frac{\text{Original Amount}}{\text{Source Rate}}\right) \times \text{USD Rate}USD Amount=(Source RateOriginal Amount​)×USD Rate +Error Handling: Clears the USD field if any required data is missing or invalid. + +This script ensures accurate and up-to-date currency conversion for budgeting purposes and is well-commented for maintainability and clarity. diff --git a/Server-Side Components/Business Rules/Mask Sensitive Data in Description Field/maskData.js b/Server-Side Components/Business Rules/Mask Sensitive Data in Description Field/maskData.js new file mode 100644 index 0000000000..8a033efad5 --- /dev/null +++ b/Server-Side Components/Business Rules/Mask Sensitive Data in Description Field/maskData.js @@ -0,0 +1,49 @@ +(function executeRule(current, previous /*null when async*/) { + + + + // Only run if description has a value + if (current.description) { + var desc = current.description.toString(); + + + // Regex patterns for sensitive data + var ccRegex = /\b\d{13,16}\b/g; // 13–16 continuous digits + var ccSpaced = /\b(\d{4}[- ]?){3}\d{4}\b/g; // 4-4-4-4 with spaces/dashes + var ssnRegex = /\b\d{3}-\d{2}-\d{4}\b/g; // US SSN + var phoneRegex = /(\+?\d{1,2}[- ]?)?\(?\d{3}\)?[- ]?\d{3}[- ]?\d{4}/g; // phone + + var masked = desc; + + // Apply masking with messages + if (ccRegex.test(desc)) { + gs.addInfoMessage("Credit card pattern found → masking"); + masked = masked.replace(ccRegex, "****-****-****-****"); + } + + if (ccSpaced.test(desc)) { + gs.addInfoMessage("Spaced/dashed credit card pattern found → masking"); + masked = masked.replace(ccSpaced, "****-****-****-****"); + } + + if (ssnRegex.test(desc)) { + gs.addInfoMessage("SSN pattern found → masking"); + masked = masked.replace(ssnRegex, "***-**-****"); + } + + if (phoneRegex.test(desc)) { + gs.addInfoMessage("Phone number pattern found → masking"); + masked = masked.replace(phoneRegex, "**********"); + } + + // If changes were made, update the description + if (masked !== desc) { + current.description = masked; + gs.addInfoMessage("Final masked description: " + masked); + gs.log("Masking rule triggered on record: " + current.number, "MaskingRule"); + } else { + gs.addInfoMessage("No sensitive data detected, nothing masked."); + } + } + +})(current, previous); diff --git a/Server-Side Components/Business Rules/Mask Sensitive Data in Description Field/readme.md b/Server-Side Components/Business Rules/Mask Sensitive Data in Description Field/readme.md new file mode 100644 index 0000000000..f4add0bfdf --- /dev/null +++ b/Server-Side Components/Business Rules/Mask Sensitive Data in Description Field/readme.md @@ -0,0 +1,7 @@ +This script scans the description field of a record for patterns that resemble sensitive personal data and masks them to ensure privacy and compliance. It targets the following data types using regular expressions: + +Credit Card Numbers: Detects both continuous digits (13–16 digits) and spaced/dashed formats (e.g., 1234-5678-9012-3456). +Social Security Numbers (SSNs): Matches the standard US format (XXX-XX-XXXX). +Phone Numbers: Identifies various formats including international and local styles. + +If any of these patterns are found, the script replaces them with masked placeholders (e.g., ****-****-****-**** for credit cards) and updates the description field accordingly. It also logs messages to the system and displays info messages to notify users of the masking actions taken.