Solved

assystETM- Setting a variable based on whether a bond exists

  • 5 January 2024
  • 2 replies
  • 30 views

Userlevel 2
Badge +5

Hello. I am trying to set a variable in an ETM data mapper based on whether an external bond exists or not. Below is my expression to set the variable to either true or false (the assyst resource for the mapper is Contact User):

if (outbound.self) {
    
    if (! outbound.self.bonds.externalIdentifier) {
        false;
    }else{
        true;
    }
}
else {
    false;
}


With my test data, I know that the bond does exists, so I believe this should be evaluating to true. However, no matter if the bond exists or not in the ips_bond table, this expression always evaluates to false.

I have tried just using outbound.self.bonds.externalIdentifier and outbound.self.externalIdentifier to bring back the identifier in the variable instead of setting it to true/false, but it always evaluates to null.

The wiki is not clear on how this value can be used.

We are running ETM 1.6 and assyst 11.4.1.

Any help appreciated.

Thanks,

Duncan

icon

Best answer by Paul McCulloch 5 January 2024, 15:15

View original

2 replies

Userlevel 2
Badge +9

The bonds are only retrieved if you explicitly ask for them via the ‘Fields’ option - in your example on the 'Record to Update’ pseudo field.

We can have multiple bonds for a single contact user - each for a specific external system. To represent this outbound.self.bonds is an array.

outbound.self.bonds.externalIdentifier is undefined which is why you always get false.

 

If you just want to know if a bond exists then you can use 

outbound.self.bonds[0];

Which is true if a bond exists and false otherwise.

 

If you do have multiple externals systems that might be bonded to a single contact user, then you need to loop through all of the bonds to find the one for the external system your are interested in.

You can use the JS filter() function to do the looping for you:

//Create an array containing only the (one) Azure AD bond
var azbonds = outbound.self.bonds && outbound.self.bonds.filter(function(b){return b.externalSystem == 'AZUREAD'});

//Create a variable containing the one Azure AD bond (if there is one)
var azbond = azbonds && azbonds[0];

We use && truthiness as shorthand way to say 

var azbond;

if(azbonds !== undefined){
azbond = azbonds[0];
}

 

 

Userlevel 2
Badge +5

Hi Paul,

Thanks for the quick answer. I knew it was something simple I was missing.

Using   if (! outbound.self.bonds[0]) is giving me an exception (javascript     IndexOutOfBoundsException - Index: 0, Size: 0) if the bond doesn’t exist. This makes sense since that statement is trying to access the first item in the array, which is empty if there are no bonds.

I ended up doing this:

 

if (outbound.self) {

   if (outbound.self.bonds.size() === 0) {
        false;
    }else{
        true;
    }
}else {
    false;
}

 

This seems to work.

 

Cheers,

Duncan

Reply