@@ -89,6 +89,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
8989 async migrate ( ) : Promise < MigrationResult [ ] > {
9090 // Get All the Active VlocityCard__c records
9191 const allCards = await this . getAllActiveCards ( ) ;
92+
9293 Logger . log ( this . messages . getMessage ( 'foundFlexCardsToMigrate' , [ allCards . length ] ) ) ;
9394
9495 // Filter out FlexCards with Angular OmniScript dependencies
@@ -1041,6 +1042,9 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
10411042 mappedObject [ CardMappings . Datasource__c ] = JSON . stringify ( datasource ) ;
10421043 }
10431044
1045+ const isCardActive : boolean = cardRecord [ `${ this . namespacePrefix } Active__c` ] ;
1046+ this . ensureCommunityTargets ( mappedObject , isCardActive ) ;
1047+
10441048 // Update all dependencies comprehensively
10451049 this . updateAllDependenciesWithRegistry ( mappedObject , invalidIpNames ) ;
10461050
@@ -1532,4 +1536,51 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
15321536
15331537 return false ;
15341538 }
1539+
1540+ /**
1541+ * Ensures that the FlexCard Definition includes required Lightning Community targets
1542+ * Adds "lightningCommunity__Page" and "lightningCommunity__Default" if missing
1543+ */
1544+ private ensureCommunityTargets ( mappedObject : any , isCardActive : boolean ) : void {
1545+ if ( ! isCardActive ) {
1546+ return ;
1547+ }
1548+
1549+ const definition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] || '{}' ) ;
1550+
1551+ if ( ! definition || ! definition . xmlObject ) {
1552+ return ;
1553+ }
1554+
1555+ // Initialize targets structure if it doesn't exist
1556+ if ( ! definition . xmlObject . targets ) {
1557+ definition . xmlObject . targets = { target : [ ] } ;
1558+ }
1559+
1560+ // Ensure target is an array
1561+ if ( ! Array . isArray ( definition . xmlObject . targets . target ) ) {
1562+ definition . xmlObject . targets . target = [ ] ;
1563+ }
1564+
1565+ const requiredTargets = [
1566+ 'lightning__RecordPage' ,
1567+ 'lightning__AppPage' ,
1568+ 'lightning__HomePage' ,
1569+ 'lightningCommunity__Page' ,
1570+ 'lightningCommunity__Default' ,
1571+ ] ;
1572+ const currentTargets = definition . xmlObject . targets . target ;
1573+
1574+ // Add missing community targets
1575+ for ( const requiredTarget of requiredTargets ) {
1576+ if ( ! currentTargets . includes ( requiredTarget ) ) {
1577+ currentTargets . push ( requiredTarget ) ;
1578+ }
1579+ }
1580+
1581+ Logger . logVerbose ( `Targets processed` ) ;
1582+
1583+ // Save the updated definition back to the mappedObject
1584+ mappedObject [ CardMappings . Definition__c ] = JSON . stringify ( definition ) ;
1585+ }
15351586}
0 commit comments