Skip to content

Commit

Permalink
Merge pull request #1698 from Accenture/bug/1692-dont-flag-common-vs-…
Browse files Browse the repository at this point in the history
…contact-issue-on-currently-running-activepublished-journeys-and-events

Bug/1692 dont flag common vs contact issue on currently running activepublished journeys and events
  • Loading branch information
JoernBerkefeld authored Sep 11, 2024
2 parents 64b785f + e316bc5 commit 9cb11a2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
8 changes: 5 additions & 3 deletions @types/lib/metadataTypes/Event.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/Event.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/Journey.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 24 additions & 11 deletions lib/metadataTypes/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ class Event extends MetadataType {
await this.postRetrieveTasks_SalesforceEntryEvents(
metadata.type,
metadata.configurationArguments,
metadata.eventDefinitionKey
metadata.eventDefinitionKey,
metadata.publishedInteractionCount >= 1
);
} catch (ex) {
Util.logger.warn(
Expand Down Expand Up @@ -670,20 +671,31 @@ class Event extends MetadataType {
/**
*
* @param {configurationArguments} ca trigger[0].configurationArguments
* @param {boolean} isPublished if the current item is published it means we do not need to do contact vs common checks
*/
static checkSalesforceEntryEvents(ca) {
static checkSalesforceEntryEvents(ca, isPublished) {
// 1 check eventDataConfig
const edcObjects = ca.eventDataConfig.objects;
const errors = [];
const dePrefixFields = {};
const dePrefixRelationshipMap = {};
const dePrefixReferenceObjectMap = {};
const checkCommon = ca.whoToInject === 'Contact ID/Lead ID (Contacts and Leads)';
// SFMC only uses "Common" to aggreagate Contacts and Leads if that was actively selected in the entry event. Also, already published journeys/events continue to work even if fields would later be changed, leading to a shift from or to the "common" fake-object.
const checkCommon =
ca.whoToInject === 'Contact ID/Lead ID (Contacts and Leads)' && !isPublished;
for (const object of edcObjects) {
// create secondary object to quickly check eventDataSummary against
dePrefixFields[object.dePrefix] = object.fields;
dePrefixRelationshipMap[object.dePrefix] = object.relationshipName;
dePrefixReferenceObjectMap[object.dePrefix] = object.referenceObject;

// if the current object is the entry object then relationshipName and referenceObject are set to empty strings because it's not "referencing" a "relationship" but just listing its own fields
dePrefixRelationshipMap[object.dePrefix] =
object.relationshipName === ''
? object.dePrefix.split(':')[0]
: object.relationshipName;
dePrefixReferenceObjectMap[object.dePrefix] =
object.referenceObject === ''
? object.dePrefix.split(':')[0]
: object.referenceObject;

// 1.1 check if fields in eventDataConfig exist in Salesforce
// if it has no value this is the entry-source object itself
Expand All @@ -698,8 +710,8 @@ class Event extends MetadataType {
) {
// check if we found fields for the object
errors.push(
`Fields for Salesforce object ${referencedObject} could not be checked. Used fields: ` +
object.fields.join(', ')
`Fields for Salesforce object ${referencedObject} could not be checked. Fields selected in entry event: ` +
object.fields.sort().join(', ')
);
} else {
// check if the fields selected in the eventDefinition are actually available
Expand Down Expand Up @@ -898,10 +910,11 @@ class Event extends MetadataType {
* @param {string} triggerType e.g. SalesforceObjectTriggerV2, APIEvent, ...
* @param {configurationArguments} ca trigger[0].configurationArguments
* @param {string} key of event / journey
* @param {string} [type] optionally provide type for error on missing configurationArguments attributes
* @param {boolean} isPublished if the current item is published it means we do not need to do contact vs common checks
* @param {string} [type] optionally provide metadatype for error on missing configurationArguments attributes
* @returns {Promise.<void>} -
*/
static async postRetrieveTasks_SalesforceEntryEvents(triggerType, ca, key, type) {
static async postRetrieveTasks_SalesforceEntryEvents(triggerType, ca, key, isPublished, type) {
if (triggerType !== 'SalesforceObjectTriggerV2' || !ca) {
return;
}
Expand Down Expand Up @@ -954,7 +967,7 @@ class Event extends MetadataType {
await this.getSalesforceObjects(ca.objectAPIName);

// check if whats on the journey matches what SF Core offers
this.checkSalesforceEntryEvents(ca);
this.checkSalesforceEntryEvents(ca, isPublished);
}

/**
Expand Down Expand Up @@ -988,7 +1001,7 @@ class Event extends MetadataType {
await this.getSalesforceObjects(ca.objectAPIName);

// check if whats on the journey matches what SF Core offers
this.checkSalesforceEntryEvents(ca);
this.checkSalesforceEntryEvents(ca, false);

// normalize payload because these fields are sometimes set as strings and sometimes as objects
// @ts-expect-error reverting this back from mcdev-format to API format
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class Journey extends MetadataType {
metadata.triggers[0].type,
metadata.triggers[0].configurationArguments,
metadata.key,
metadata.status === 'Published',
this.definition.type
);
} catch (ex) {
Expand Down

0 comments on commit 9cb11a2

Please sign in to comment.