Compare two fields then take action?

Amy_Lepre
Level 7

Compare two fields then take action?

I have a use case where I need to compare two fields and then take two different actions depending on if the fields match or not. I've tried doing this a number of ways using tokens and nothing has worked. I contacted support and they tell me this is not possible to do in Marketo which I find hard to believe.

Some of the methods I've tried:

Smart List: Trigger - Lead was added to list; Filter - Field1 is {{lead.Field2}}

Flow: Add lead to matched list

Smart List: Trigger - Lead was added to list

Flow: Choice 1: Field1 is {{lead.Field2}}, add to matched list and Choice 2: Field1 is not {{lead.Field2}}, add to non-matched list

Smart List: Trigger - Data value changes for Field1 with one constraint: New value is {{lead.Field2}}

Flow: Add lead to matched list

There has to be a way to look at two field values, compare them and then take an action based on if they match or not. Any ideas?

13 REPLIES 13
SanfordWhiteman
Level 10 - Community Moderator

Re: Compare two fields then take action?

You could build a webhook to return a match (stored in a 3rd field)... if that's in your wheelhouse.

Josh_Hill13
Level 10 - Champion Alumni

Re: Compare two fields then take action?

There is a good guide on that from RingLead.

Right now there is no comparison function or regex in Marketo.

Alok_Ramsisaria
Level 10

Re: Compare two fields then take action?

Can you please share the link where we can access Ringlead guide on this topic?

Prakash_Mohanda
Level 2

Re: Compare two fields then take action?

Hi Sanford

I am trying to do something similar where i am trying to compare two email ID values with marketo and do different actions based on the comparison result.

Is there a more updated solution to this now in ,marketo or is this still a webhook solution?

If its a webhook is there an example of how this can be done using a webhook? will match (Yes/No) need to be stored a separate field?

SanfordWhiteman
Level 10 - Community Moderator

Re: Compare two fields then take action?

Still a webhook thing.

will match (Yes/No) need to be stored a separate field?

You don't need to have a separate field, as you can use the Webhook is Called trigger to parse the true/false result for something this simple.

The exact flavor of webhook engine you use also doesn't matter. Obviously I have my preferences, but the idea is always to do a case-insensitive comparison and return one of two values that represent true and false (which could be the characters t-r-u-e and f-a-l-s-e, numbers 0 and 1, characters y-e-s or n-o, etc.). It's most common to send a JSON boolean true/false. But since you're parsing with Webhook is Called, it's actually better to send plain text (just the true/false result).

Mike_Hardwicke_
Level 1

Re: Compare two fields then take action?

Sanford Whiteman​ can you share how you could accomplish that with flow boost?

SanfordWhiteman
Level 10 - Community Moderator

Re: Compare two fields then take action?

can you share how you could accomplish that with flow boost?

Sure, checking two fields for equality is just:

var isMatched = {{Lead.Field 1}} === {{Lead.Field 2}};

isMatched will be boolean true or false in the response.

If you happened to have a semicolon-delimited list in one field and wanted to look the other field up in it:

var isInList =  {{Lead.Delimited String Field}}.split(";").includes({{Lead.Field 1}});

If you want to trigger on Data Value Changes, which wouldn't happen if the value was already true, you can update a sort of "sentinel" field to the current timestamp (as an alternative to using Webhook is Called):

if (isMatched) {

    var lastMatchedTS = new Date().toISOString();

}

SanfordWhiteman
Level 10 - Community Moderator

Re: Compare two fields then take action?

Also, couple of other hints in the general realm of "comparison"...

List Intersection

If you have 2 different comma-delimited Marketo fields and want to see if they have any internal item in common:

var list1 = {{Lead.Delimited String Field}}.split(";"),

    list2 = {{Lead.Another Delimited String Field}}.split(";");

    listsMatchCommonItem = list1.some( itm => list2.includes(itm) );

Differing sensitivity

To do a accent-sensitive, but case-insensitive, compare between 2 string fields, :

var isMatchedAccentNoCase = !{{Lead.Field 1}}.localeCompare( {{Lead.Field 2}} , "standard", { sensitivity: "accent" } );

If you want "É" and "E" to compare equal then use { sensitivity: "base" }.

The variations in sensitivity are fascinatingly necessary, depending on what you're trying to do and what you know about your input. And don't get me started about how to do the same thing in a Velocity token!

More Notes

The above are standard JavaScript functions, nothing proprietary to FB, though if you're playing around with them offline, they won't work in all browsers (not just the usual suspect, IE, but localeCompare was only enhanced in Safari 10).

Old-school strict string equality (===) is almost the same as:

var isMatchedLikeTripleEquals = !{{Lead.Field 1}}.localeCompare( {{Lead.Field 2}} , "standard", { sensitivity: "variant" } );

But not quite. I'll let you figure out the difference!

Vlada_Prasolova
Level 5

Re: Compare two fields then take action?

will this work if my fields are dates?