Expand my Community achievements bar.

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.

3 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

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!