Expand my Community achievements bar.

Help shape the future of AI assistance by participating in this quick card sorting activity. Your input will help create a more effective system that better serves your needs and those of your colleagues.
SOLVED

Event Forwarding - Error "Referenced Data Element are not added to the build: arc.event.xdm"

Avatar

Level 2

Hi there,

 

I am trying to use Event Forwarding to send data to other systems dynamically. The scenario is multi-brand, so I have different XDM schema fields referring to the same concept (e.g.: identities.brand1.ecid, identities.brand2.ecid). I want Event Forwarding to adapt the request depending on the origin (brand) of the data, so I have decided to create a dynamic Data Element via custom JS code:

 

 

let ecid;
var xdmObject = getDataElementValue('arc.event.xdm');

if(xdmObject){
    if (url.includes("brand1.com")) {
      ecid = xdmObject._sandboxname.identities.brand1.profile.ecid.id;
  } else if (url.includes("brand2.com")) {
      ecid = xdmObject._sandboxname.identities.brand2.profile.ecid.id;
  } else {
      // Handle cases where the URL does not match any known hosts
      console.warn('Unknown host in URL:', url);
      ecid = "";
  }
}

return ecid

 

 

Nevertheless, when I try to Build the code I get the next error:

 

There was an error minifying your custom code.
Referenced DataElements are not added to the build: arc.event.xdm
 
Where am I doing wrong? I was assuming "arc.event.xdm" could be directly accessed from Event Forwarding custom code. Could you please provide some guidance on this?
 
Thanks in advance
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @jlasso71 

arc.event.xdm is actually a path to the request payload. Have you created a data element with exactly this name?

If so, make sure to include it in your Library.

bjoern__koth_0-1733217727549.png

 

If you are just using custom code, you won't need to pull this data element in, since you can just directly reference it from your custom code.

 

arc.event.xdm.path.to.data

 

Just beware that you must make sure your code checks for anything being unset in your object structure.

Luckily, nowadays, this is pretty easy in Javascript and you can use Optional Chaining to access anything at any depth in your object structure, by using "?." instead of "." to access the next level. As soon as any part is not set, it will stop executing and not fail.

 

// the old world
if (arc && arc.event && arc.event.xdm && arc.event.xdm._sandboxname && arc.event.xdm._sandboxname.identities 
    && arc.event.xdm._sandboxname.identities.brand1 && arc.event.xdm._sandboxname.identities.brand1.profile 
    && arc.event.xdm._sandboxname.identities.brand1.profile.ecid && arc.event.xdm._sandboxname.identities.brand1.profile.ecid.id) {
    // boy this is long!
}
// the new world
if (arc?.event?.xdm?._sandboxname?.identities?.brand1?.profile?.ecid?.id) {
    // much better
}

 

In other words, if you were accessing arc.event.xdm.hello.world through code, and any part of this path is not set, you would get an error.

 

So, if you know already that you have a specific number of brands, maybe you are better off with creating dedicated data elements

bjoern__koth_1-1733218036398.png

since access to this Path is implicitly failsafe.

Cheers from Switzerland!


View solution in original post

6 Replies

Avatar

Community Advisor

Hello @jlasso71  You can create rules.

 

First store the the value of URL in a data element like this:

_Manoj_Kumar__0-1733193122601.png

 

 

Then create a URL to check the value and fire the custom code

_Manoj_Kumar__1-1733193151355.png_Manoj_Kumar__2-1733193274400.png_Manoj_Kumar__3-1733193289651.png

 


     Manoj
     Find me on LinkedIn

Avatar

Level 2

Hi Manoj,

 

Thanks for your prompt response. Your solution makes sense but it requires one rule per brand (I have more than 20 brands in some cases). Also, I would need a Data Element per each XDM path, which is something I would definitely like to avoid.

 

Have you tried to access "arc.event.xdm" directly from Event Forwarding custom code? 

 

Best regards,

Avatar

Correct answer by
Community Advisor

Hi @jlasso71 

arc.event.xdm is actually a path to the request payload. Have you created a data element with exactly this name?

If so, make sure to include it in your Library.

bjoern__koth_0-1733217727549.png

 

If you are just using custom code, you won't need to pull this data element in, since you can just directly reference it from your custom code.

 

arc.event.xdm.path.to.data

 

Just beware that you must make sure your code checks for anything being unset in your object structure.

Luckily, nowadays, this is pretty easy in Javascript and you can use Optional Chaining to access anything at any depth in your object structure, by using "?." instead of "." to access the next level. As soon as any part is not set, it will stop executing and not fail.

 

// the old world
if (arc && arc.event && arc.event.xdm && arc.event.xdm._sandboxname && arc.event.xdm._sandboxname.identities 
    && arc.event.xdm._sandboxname.identities.brand1 && arc.event.xdm._sandboxname.identities.brand1.profile 
    && arc.event.xdm._sandboxname.identities.brand1.profile.ecid && arc.event.xdm._sandboxname.identities.brand1.profile.ecid.id) {
    // boy this is long!
}
// the new world
if (arc?.event?.xdm?._sandboxname?.identities?.brand1?.profile?.ecid?.id) {
    // much better
}

 

In other words, if you were accessing arc.event.xdm.hello.world through code, and any part of this path is not set, you would get an error.

 

So, if you know already that you have a specific number of brands, maybe you are better off with creating dedicated data elements

bjoern__koth_1-1733218036398.png

since access to this Path is implicitly failsafe.

Cheers from Switzerland!


Avatar

Level 2

Hi @bjoern__koth ,

 

Thanks for your response, your solution using Optional Chaining is really powerful. The problem we have is that when accessing arc.event.xdm.hello.world through code we are not even able to publish the changes:

 

There was an error minifying your custom code.
Referenced DataElements are not added to the build: arc.event.xdm

 

Regarding using failsafe data elements, we do not want to create dedicated data elements per brand due to operative costs (20-30 brands * 5-10 paths = 100-300 data elements).

 

Best regards,

Avatar

Level 1

Can you post your code or screenshot of it? Should be an easy explanation for the error.

if you don't want to share the code publicly, you can also send me a DM

Avatar

Community Advisor

@jlasso71 as you may have noticed, this was me from my phone but obviously a different account above xD

If you want to share your code with me, drop me a DM

Cheers from Switzerland!