Created
February 2, 2026 23:33
-
-
Save trycf/ec72171f4477b6c45d397375018cac65 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <cfscript> | |
| String function replaceEquivalent(required numeric phoneId, required String productList) { | |
| var i = createObject("java", "java.util.ArrayList").init(); | |
| i.add({"product_from": 12345, "product_to": 112233, "requires_service_validation": 1}); | |
| i.add({"product_from": 23456, "product_to": 112233, "requires_service_validation": 0}); | |
| i.add({"product_from": 34567, "product_to": 112233, "requires_service_validation": 1}); | |
| i.add({"product_from": 45678, "product_to": 112233, "requires_service_validation": 0}); | |
| var iter = i.iterator(); | |
| var replaced = ''; | |
| var forMigration = arguments.productList; | |
| while (iter.hasNext()) { | |
| var migration = iter.next(); | |
| var sourceIndex = listFind(forMigration, migration.product_from); | |
| var hasMigration = sourceIndex > 0; | |
| if (hasMigration) { | |
| var requiresServiceValidation = migration.requires_service_validation > 0; | |
| var valid = true; | |
| if (requiresServiceValidation) { | |
| var item = { active_from: '2025-05-11 14:43:40' }; | |
| if (migration.product_from == 12345) { | |
| item.phone_id = arguments.phoneId; | |
| } | |
| var notFound = !isDefined('item.phone_id'); | |
| var active = | |
| (isDefined('item.active_from') && isDefined('item.phone_id') && Now() >= item.active_from) || | |
| (!isDefined('item.active_from') && isDefined('item.phone_id')); | |
| valid = notFound || active; | |
| var d = { product_from: migration.product_from, notFound: notFound, active: active, valid: valid }; | |
| writeDump(d); | |
| } | |
| if (valid) { | |
| replaced = listAppend(replaced, migration.product_to); | |
| forMigration = listDeleteAt(forMigration, sourceIndex); | |
| } | |
| } | |
| } | |
| if (listLen(forMigration) > 0) { | |
| replaced = listAppend(replaced, forMigration); | |
| } | |
| return replaced; | |
| } | |
| l = replaceEquivalent(121212, '12345,23456,34567,98765'); | |
| writeDump(l); | |
| </cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment