SOLVED

Re: How to filter specific Custom Objects?

Go to solution
Anonymous
Not applicable

How to filter specific Custom Objects?

Hi all,

I record very specific events into Custom Objects linked to Leads. For example if a user has clicked on a specific link that I'd like to track, I'll create a Custom Object out of that event and this CO will include extra data than the one that Marketo holds in the Activity Log. (which is why I create a CO instead of using the Activity Log)

I'd like to be able to target COs that have specific properties based on the data that is in their fields, for example:

- Has CO

- dateTime is in timeframe Yesterday

- partnerURL is not empty

If I create a Smart List with this criteria and it generates a list of leads that are linked to COs that match this criteria. Then I send an email each day with a personalized message and the partnerURL link so that the user can click on it. To do this I fetch the size of the CO and then retrieve the last CO created for that user.

Except in some cases I have recorded multiple COs on the same day for a same user and only one of the COs really matches the criteria, and worst of all, the latest CO does NOT match the criteria. So when I build the email dynamically by fetching the last CO, the link doesn't work because that CO did not have a partnerURL.

Any idea how I can filter out the COs that don't match the criteria I used in the Smart List? The issue is that the Smart List fetches a list of Leads, whereas I should fetch a list of COs, and if possible only those that match my criteria.

Thanks for your help!

Thomas

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How to filter specific Custom Objects?

Yes you're absolutely right, it seems it's the only solution I have. Just to make sure I understand correctly, you suggest I loop through the lead's custom objects, from the most recent to the least recent, checking in each iteration if partnerURL is empty or not, and using BREAK when it isn't, recording the index so that I can then retrieve all the content I need from that index's CO. Is this correct?

You don't need to record the index. You're iterating over an ArrayList, which contains an object at every index. So just store the object when you find the first match.

## You can also use this var to hold the default event

#set( $lastInterestingEvent = {} )

## Guard against bad inputs (null or empty object list)

#if( $EventList && !$EventList.isEmpty() )

    ## Loop backwards through ArrayList (standard foreach is fwd only)

    #foreach( $idx in [$math.sub($EventList.size(),1)..0] )

        #set( $event = $EventList[$idx] )

        #if( !$event.partnerURL.isEmpty() )

            #set( $lastInterestingEvent = $event )

            #break($foreach)

        #end

    #end

#end

Partner URL is: ${lastInterestingEvent.partnerURL}

http://developers.marketo.com/email-scripting/examples/

I couldn't vouch for any of those. Two of them have gaping bugs.

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: How to filter specific Custom Objects?

So when I build the email dynamically by fetching the last CO, the link doesn't work because that CO did not have a partnerURL.

I don't understand why you don't filter the COList to get the last one with a partnerURL.

Anonymous
Not applicable

Re: How to filter specific Custom Objects?

Hi Sanford!

Yes you're absolutely right, it seems it's the only solution I have. Just to make sure I understand correctly, you suggest I loop through the lead's custom objects, from the most recent to the least recent, checking in each iteration if partnerURL is empty or not, and using BREAK when it isn't, recording the index so that I can then retrieve all the content I need from that index's CO. Is this correct?

Do you happen to have a code sample for this type of loop? I found this, the 1st sample seems to be the way to go:

http://developers.marketo.com/email-scripting/examples/

Thanks,

Thomas

SanfordWhiteman
Level 10 - Community Moderator

Re: How to filter specific Custom Objects?

Yes you're absolutely right, it seems it's the only solution I have. Just to make sure I understand correctly, you suggest I loop through the lead's custom objects, from the most recent to the least recent, checking in each iteration if partnerURL is empty or not, and using BREAK when it isn't, recording the index so that I can then retrieve all the content I need from that index's CO. Is this correct?

You don't need to record the index. You're iterating over an ArrayList, which contains an object at every index. So just store the object when you find the first match.

## You can also use this var to hold the default event

#set( $lastInterestingEvent = {} )

## Guard against bad inputs (null or empty object list)

#if( $EventList && !$EventList.isEmpty() )

    ## Loop backwards through ArrayList (standard foreach is fwd only)

    #foreach( $idx in [$math.sub($EventList.size(),1)..0] )

        #set( $event = $EventList[$idx] )

        #if( !$event.partnerURL.isEmpty() )

            #set( $lastInterestingEvent = $event )

            #break($foreach)

        #end

    #end

#end

Partner URL is: ${lastInterestingEvent.partnerURL}

http://developers.marketo.com/email-scripting/examples/

I couldn't vouch for any of those. Two of them have gaping bugs.