diff --git a/utilities/boundary-bulk-bff/src/server/utils/boundaryUtils.ts b/utilities/boundary-bulk-bff/src/server/utils/boundaryUtils.ts index 0ba03bc0148..a6469119e7e 100644 --- a/utilities/boundary-bulk-bff/src/server/utils/boundaryUtils.ts +++ b/utilities/boundary-bulk-bff/src/server/utils/boundaryUtils.ts @@ -252,6 +252,37 @@ function generateElementCode(sequence: any, parentElement: any, parentBoundaryCo return code.trim(); } +function modifyElementCodesMap(elementCodesMap: any) { + const set = new Set(); + const specialCharsRegex = /[^\w\s]/g; // Regular expression to match any character that is not a word character or space + + // Iterate over each [key, value] pair in elementCodesMap using forEach + elementCodesMap.forEach((value: any, key: any) => { + let modifiedValue = value.replace(specialCharsRegex, '_').trim(); // Replace special characters and spaces with underscore + let modifiedTempValue = modifiedValue; // Store the initial modified value + let count = 1; + + // Generate a unique modified value + while (set.has(modifiedValue)) { + // If it exists, append _ to modifiedValue + modifiedValue = `${modifiedTempValue}_${count}`; + count++; + } + + // Add the modified (or original) value to the set + set.add(modifiedValue); + + // Update the map with the modified value + elementCodesMap.set(key, modifiedValue); + }); + +} + + + + + + async function getAutoGeneratedBoundaryCodes(boundaryList: any, childParentMap: any, elementCodesMap: any, countMap: any, request: any) { // Initialize an array to store column data const columnsData: { key: string, value: string }[][] = []; @@ -301,6 +332,7 @@ async function getAutoGeneratedBoundaryCodes(boundaryList: any, childParentMap: } } } + modifyElementCodesMap(elementCodesMap) return elementCodesMap; // Return the updated element codes map }