Skip to content

Commit 15e114c

Browse files
Reserved Key and Duplicate Element name
1 parent 13fa275 commit 15e114c

File tree

4 files changed

+106
-7
lines changed

4 files changed

+106
-7
lines changed

messages/assess.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,6 @@
184184
"errorCheckingGlobalAutoNumber": "We couldn’t check whether the Global Auto Number setting is enabled: %s. Try again later.",
185185
"errorMigrationMessage": "Error migrating object: %s",
186186
"nameMappingUndefined": "Name Mapping is undefined",
187-
"experienceSiteException": "Exception occurred while processing experience sites"
187+
"experienceSiteException": "Exception occurred while processing experience sites",
188+
"reservedKeysFoundInPropertySet": "Reserved keys found in any of output response transformation fields: %s."
188189
}

messages/migrate.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
"missingInfo": "Info is missing",
198198
"errorCheckingGlobalAutoNumber": "We couldn’t check whether the Global Auto Number setting is enabled: %s. Try again later.",
199199
"errorMigrationMessage": "Error migrating object: %s",
200-
"nameMappingUndefined": "Name Mapping is undefined",
201-
"experienceSiteException": "Exception occurred while processing experience sites"
202-
}
200+
"experienceSiteException": "Exception occurred while processing experience sites",
201+
"reservedKeysFoundInPropertySet": "Reserved keys found in any of output response transformation fields: %s.",
202+
"nameMappingUndefined": "Name Mapping is undefined"
203+
}

src/migration/omniscript.ts

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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') {
@@ -648,10 +688,17 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
648688
// Get All elements for each OmniScript__c record(i.e IP/OS)
649689
const elements = await this.getAllElementsForOmniScript(recordId);
650690
if (omniscript[`${this.namespacePrefix}IsProcedure__c`] === true) {
691+
// Check for reserved keys in PropertySet for Integration Procedures
692+
const foundReservedKeys = new Set<string>();
693+
651694
// do the formula replacement from custom to standard notation
652695
if (functionDefinitionMetadata.length > 0 && elements.length > 0) {
653696
for (let ipElement of elements) {
654697
if (ipElement[`${this.namespacePrefix}PropertySet__c`] != null) {
698+
// Check for reserved keys while processing the PropertySet
699+
const propertySet = JSON.parse(ipElement[`${this.namespacePrefix}PropertySet__c`] || '{}');
700+
this.collectReservedKeys(propertySet, foundReservedKeys);
701+
655702
var originalString = ipElement[`${this.namespacePrefix}PropertySet__c`];
656703
try {
657704
originalString = getReplacedString(
@@ -669,6 +716,24 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
669716
}
670717
}
671718
}
719+
720+
// If reserved keys found, skip this IP
721+
if (foundReservedKeys.size > 0) {
722+
const reservedKeysList = Array.from(foundReservedKeys).join(', ');
723+
const skippedResponse: UploadRecordResult = {
724+
referenceId: recordId,
725+
id: '',
726+
success: false,
727+
hasErrors: false,
728+
errors: [],
729+
warnings: [this.messages.getMessage('reservedKeysFoundInPropertySet', [reservedKeysList])],
730+
newName: '',
731+
skipped: true,
732+
};
733+
osUploadInfo.set(recordId, skippedResponse);
734+
originalOsRecords.set(recordId, omniscript);
735+
continue;
736+
}
672737
}
673738

674739
// Perform the transformation for OS/IP Parent Record from OmniScript__c
@@ -918,9 +983,8 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
918983
}
919984
}
920985

921-
let finalKey = `${oldrecord[this.namespacePrefix + 'Type__c']}${
922-
oldrecord[this.namespacePrefix + 'SubType__c']
923-
}${oldrecord[this.namespacePrefix + 'Language__c']}`;
986+
let finalKey = `${oldrecord[this.namespacePrefix + 'Type__c']}${oldrecord[this.namespacePrefix + 'SubType__c']
987+
}${oldrecord[this.namespacePrefix + 'Language__c']}`;
924988

925989
finalKey = finalKey.toLowerCase();
926990
if (storage.osStorage.has(finalKey)) {
@@ -1306,6 +1370,37 @@ export class OmniScriptMigrationTool extends BaseMigrationTool implements Migrat
13061370
return Object.keys(OmniScriptDefinitionMappings);
13071371
}
13081372

1373+
/**
1374+
* Collects reserved keys found in PropertySet tagsToValidate
1375+
* @param propertySet - The PropertySet JSON object to validate
1376+
* @param foundReservedKeys - Set to collect found reserved keys
1377+
*/
1378+
private collectReservedKeys(propertySet: any, foundReservedKeys: Set<string>): void {
1379+
// Iterate through each tag that needs validation
1380+
for (const tagToValidate of this.tagsToValidate) {
1381+
const tagValue = propertySet[tagToValidate];
1382+
1383+
if (tagValue) {
1384+
if (typeof tagValue === 'object' && tagValue !== null) {
1385+
// If it's an object, check all its keys
1386+
const keys = Object.keys(tagValue);
1387+
for (const key of keys) {
1388+
if (this.reservedKeys.has(key)) {
1389+
foundReservedKeys.add(key);
1390+
}
1391+
}
1392+
} else if (typeof tagValue === 'string') {
1393+
// If it's a string, check if the value itself is a reserved key
1394+
if (this.reservedKeys.has(tagValue)) {
1395+
foundReservedKeys.add(tagValue);
1396+
}
1397+
}
1398+
}
1399+
}
1400+
}
1401+
1402+
1403+
13091404
private sleep() {
13101405
return new Promise((resolve) => {
13111406
setTimeout(resolve, 5000);

src/utils/constants/documentRegistry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ export const documentRegistry = {
5858
duplicateCardNameMessage: 'https://help.salesforce.com/s/articleView?id=xcloud.os_clone_a_flexcard.htm&type=5',
5959
duplicateGlobalAutoNumberNameMessage:
6060
'https://help.salesforce.com/s/articleView?id=xcloud.os_omnistudio_naming_conventions.htm&type=5',
61+
reservedKeysFoundInPropertySet:
62+
'https://help.salesforce.com/s/articleView?id=xcloud.os_omnistudio_naming_conventions.htm&type=5',
6163
};

0 commit comments

Comments
 (0)