Skip to content

Commit b7c72d8

Browse files
Merge pull request #360 from mdmehran-qureshi/prerelease/develop-ga
Function enhancements
2 parents 475888e + 6a82bb1 commit b7c72d8

File tree

4 files changed

+138
-7
lines changed

4 files changed

+138
-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: 130 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') {
@@ -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);

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)