Hi all and support team, I am trying to send an E...
# support
m
Hi all and support team, I am trying to send an EVENT to a SPECIFIC Destination. I tried to update the
metadata(event).destinationId
but does not work obviously. Here my transformation so far:
Copy code
export function transformEvent(event, metadata) {
    const identifyChannelId = "2IgciJhF4ItDIbBGyGdomODk9R2";
    const trackChannelId = "2KSWHpnG6cSXbR6GDo3RbXfaI6y";
    
    const eventType = event.type;
  
    if (eventType == "identify") {
        metadata(event).destinationId = identifyChannelId;
    }
    
    if (eventType == "track") {
        metadata(event).destinationId = trackChannelId;
    }
    
    return event;
}
h
You will have to send the event back into rudder with the correct source for this to work
or why not a source that has both destinations attached and a transform for each destination that drops the event if your not interested in it
m
@hundreds-lifeguard-65770 thanks. I already set 2 destinations (1 Flutter source - 2 Slacks destinations). But i don't want to DROP an event , I want to redirect to the corresponding SOURCE. Any ideas ?
h
ok so all events will be going to both destinations
what you need to do is drop the event you dont want going to the relevant destination - it wont get dropped from the other - separate pipelines - so a transformation per destination that simply drops the event when not required
Copy code
export function transformEvent(event, metadata) {
    if (eventType == "identify") {
        return;
    }
}
transformations are linked to a destination not source
m
@hundreds-lifeguard-65770 Thanks a lot, it was pretty obvious. I did as you said , created 1 transformations per DESTINATION. I will be able to route events according to their TYPE or NAME or whatever 👍 💪
h
cool 👍
you could use the same transform and just use a map at the top
m
Not sure hat you mean 🤔
Do yo have a code example of the
map
?
h
1 tick
const eventMap = [{
"event": "alias",
"dest": "2IgciJhF4ItDIbBGyGdomODk9R2"
},
{
"event": "identity",
"dest": "2KSWHpnG6cSXbR6GDo3RbXfaI6y"
}]
export function transformEvent(event, metadata) {
//get dest for this event
let dest = eventMap.find(e => e.dest === metadata(event).destinationId);
if (dest && dest.name === event.event){
return event;
}
return;
}
simply - if the current events destination is in the map, check the event type matches else return null
m
@hundreds-lifeguard-65770 Ha right. Much much better to keep only one TRANSFORMATION. I really have to think in term of FILTERING events and NOT REDIRECTING events. Thanks a lot for the time spent 🙏
h
no worries