@@ -43,6 +43,12 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
4343 private readonly exportType : OmniScriptExportType ;
4444 private readonly allVersions : boolean ;
4545
46+ // Reserved keys that should not be used for storing output
47+ private readonly reservedKeys = new Set < string > ( [ 'Request' , 'Response' , 'Condition' ] ) ;
48+
49+ // Tags to validate in PropertySet for reserved key usage
50+ private readonly tagsToValidate = new Set < string > ( [ 'additionalOutput' ] ) ;
51+
4652 // constants
4753 private readonly OMNISCRIPT = 'OmniScript' ;
4854
@@ -358,11 +364,31 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
358364 const dependenciesLWC : nameLocation [ ] = [ ] ;
359365
360366 //const missingRA: string[] = [];
367+
368+ // Check for duplicate element names within the same OmniScript
369+ const elementNames = new Set < string > ( ) ;
370+ const duplicateElementNames = new Set < string > ( ) ;
371+
372+ // Track reserved keys found in PropertySet
373+ const foundReservedKeys = new Set < string > ( ) ;
374+
375+ for ( const elem of elements ) {
376+ const elemName = elem [ 'Name' ] ;
377+ if ( elementNames . has ( elemName ) ) {
378+ duplicateElementNames . add ( elemName ) ;
379+ } else {
380+ elementNames . add ( elemName ) ;
381+ }
382+ }
383+
361384 for ( const elem of elements ) {
362385 const type = elem [ this . namespacePrefix + 'Type__c' ] ;
363386 const elemName = `${ elem [ 'Name' ] } ` ;
364387 const propertySet = JSON . parse ( elem [ this . namespacePrefix + 'PropertySet__c' ] || '{}' ) ;
365388
389+ // Collect reserved keys from PropertySet
390+ this . collectReservedKeys ( propertySet , foundReservedKeys ) ;
391+
366392 // Check for OmniScript dependencies
367393 if ( type === 'OmniScript' ) {
368394 const nameVal = `${ elemName } ` ;
@@ -493,6 +519,20 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
493519 existingOmniscriptNames . add ( recordName ) ;
494520 }
495521
522+ // Add warning for duplicate element names within the same OmniScript
523+ if ( duplicateElementNames . size > 0 ) {
524+ const duplicateNamesList = Array . from ( duplicateElementNames ) . join ( ', ' ) ;
525+ warnings . unshift ( this . messages . getMessage ( 'invalidOrRepeatingOmniscriptElementNames' , [ duplicateNamesList ] ) ) ;
526+ assessmentStatus = 'Needs Manual Intervention' ;
527+ }
528+
529+ // Add warning for reserved keys found in PropertySet
530+ if ( foundReservedKeys . size > 0 ) {
531+ const reservedKeysList = Array . from ( foundReservedKeys ) . join ( ', ' ) ;
532+ warnings . unshift ( this . messages . getMessage ( 'reservedKeysFoundInPropertySet' , [ reservedKeysList ] ) ) ;
533+ assessmentStatus = 'Needs Manual Intervention' ;
534+ }
535+
496536 if ( omniProcessType === this . OMNISCRIPT ) {
497537 const type = omniscript [ this . namespacePrefix + 'IsLwcEnabled__c' ] ? 'LWC' : 'Angular' ;
498538 if ( type === 'Angular' ) {
@@ -647,11 +687,50 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
647687
648688 // Get All elements for each OmniScript__c record(i.e IP/OS)
649689 const elements = await this . getAllElementsForOmniScript ( recordId ) ;
690+
691+ // Check for duplicate element names within the same OmniScript
692+ const elementNames = new Set < string > ( ) ;
693+ const duplicateElementNames = new Set < string > ( ) ;
694+
695+ for ( const elem of elements ) {
696+ const elemName = elem [ 'Name' ] ;
697+ if ( elementNames . has ( elemName ) ) {
698+ duplicateElementNames . add ( elemName ) ;
699+ } else {
700+ elementNames . add ( elemName ) ;
701+ }
702+ }
703+
704+ // If duplicate element names found, skip this OmniScript
705+ if ( duplicateElementNames . size > 0 ) {
706+ const duplicateNamesList = Array . from ( duplicateElementNames ) . join ( ', ' ) ;
707+ const skippedResponse : UploadRecordResult = {
708+ referenceId : recordId ,
709+ id : '' ,
710+ success : false ,
711+ hasErrors : false ,
712+ errors : [ ] ,
713+ warnings : [ this . messages . getMessage ( 'invalidOrRepeatingOmniscriptElementNames' , [ duplicateNamesList ] ) ] ,
714+ newName : '' ,
715+ skipped : true ,
716+ } ;
717+ osUploadInfo . set ( recordId , skippedResponse ) ;
718+ originalOsRecords . set ( recordId , omniscript ) ;
719+ continue ;
720+ }
721+
650722 if ( omniscript [ `${ this . namespacePrefix } IsProcedure__c` ] === true ) {
723+ // Check for reserved keys in PropertySet for Integration Procedures
724+ const foundReservedKeys = new Set < string > ( ) ;
725+
651726 // do the formula replacement from custom to standard notation
652727 if ( functionDefinitionMetadata . length > 0 && elements . length > 0 ) {
653728 for ( let ipElement of elements ) {
654729 if ( ipElement [ `${ this . namespacePrefix } PropertySet__c` ] != null ) {
730+ // Check for reserved keys while processing the PropertySet
731+ const propertySet = JSON . parse ( ipElement [ `${ this . namespacePrefix } PropertySet__c` ] || '{}' ) ;
732+ this . collectReservedKeys ( propertySet , foundReservedKeys ) ;
733+
655734 var originalString = ipElement [ `${ this . namespacePrefix } PropertySet__c` ] ;
656735 try {
657736 originalString = getReplacedString (
@@ -669,6 +748,24 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
669748 }
670749 }
671750 }
751+
752+ // If reserved keys found, skip this IP
753+ if ( foundReservedKeys . size > 0 ) {
754+ const reservedKeysList = Array . from ( foundReservedKeys ) . join ( ', ' ) ;
755+ const skippedResponse : UploadRecordResult = {
756+ referenceId : recordId ,
757+ id : '' ,
758+ success : false ,
759+ hasErrors : false ,
760+ errors : [ ] ,
761+ warnings : [ this . messages . getMessage ( 'reservedKeysFoundInPropertySet' , [ reservedKeysList ] ) ] ,
762+ newName : '' ,
763+ skipped : true ,
764+ } ;
765+ osUploadInfo . set ( recordId , skippedResponse ) ;
766+ originalOsRecords . set ( recordId , omniscript ) ;
767+ continue ;
768+ }
672769 }
673770
674771 // Perform the transformation for OS/IP Parent Record from OmniScript__c
@@ -918,9 +1015,8 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
9181015 }
9191016 }
9201017
921- let finalKey = `${ oldrecord [ this . namespacePrefix + 'Type__c' ] } ${
922- oldrecord [ this . namespacePrefix + 'SubType__c' ]
923- } ${ oldrecord [ this . namespacePrefix + 'Language__c' ] } `;
1018+ let finalKey = `${ oldrecord [ this . namespacePrefix + 'Type__c' ] } ${ oldrecord [ this . namespacePrefix + 'SubType__c' ]
1019+ } ${ oldrecord [ this . namespacePrefix + 'Language__c' ] } `;
9241020
9251021 finalKey = finalKey . toLowerCase ( ) ;
9261022 if ( storage . osStorage . has ( finalKey ) ) {
@@ -1306,6 +1402,37 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
13061402 return Object . keys ( OmniScriptDefinitionMappings ) ;
13071403 }
13081404
1405+ /**
1406+ * Collects reserved keys found in PropertySet tagsToValidate
1407+ * @param propertySet - The PropertySet JSON object to validate
1408+ * @param foundReservedKeys - Set to collect found reserved keys
1409+ */
1410+ private collectReservedKeys ( propertySet : any , foundReservedKeys : Set < string > ) : void {
1411+ // Iterate through each tag that needs validation
1412+ for ( const tagToValidate of this . tagsToValidate ) {
1413+ const tagValue = propertySet [ tagToValidate ] ;
1414+
1415+ if ( tagValue ) {
1416+ if ( typeof tagValue === 'object' && tagValue !== null ) {
1417+ // If it's an object, check all its keys
1418+ const keys = Object . keys ( tagValue ) ;
1419+ for ( const key of keys ) {
1420+ if ( this . reservedKeys . has ( key ) ) {
1421+ foundReservedKeys . add ( key ) ;
1422+ }
1423+ }
1424+ } else if ( typeof tagValue === 'string' ) {
1425+ // If it's a string, check if the value itself is a reserved key
1426+ if ( this . reservedKeys . has ( tagValue ) ) {
1427+ foundReservedKeys . add ( tagValue ) ;
1428+ }
1429+ }
1430+ }
1431+ }
1432+ }
1433+
1434+
1435+
13091436 private sleep ( ) {
13101437 return new Promise ( ( resolve ) => {
13111438 setTimeout ( resolve , 5000 ) ;
0 commit comments