Re: Set Custom Object with Opportunity Item

michaelstancil
Level 3

Hi all,

 

I'm trying to set a custom object to an email that is within an opportunity item so that I can use that newly set custom object to send a notification email via the flow step. This is because we send an email to a client with opportunity-specific info, and then we want to alert the sales rep of that email, but for other reasons, not all sales reps are on the lead level, so I need to surface them.

 

I've created a token that I've placed within the email that goes out to the client, and the referenced items are checked on the right, however, the values don't update. 

 

#set( ${OpportunityList.get(0).SalesRepEmail__c} = ${lead.CustomObjectEmail})

 

Any thoughts? 

Tags (1)
12 REPLIES 12
SanfordWhiteman
Level 10 - Community Moderator

@michaelstancil I’ll let you and Jo continue with the business requirements discussion, but be aware there are problems with this code on its own:

#set( ${OpportunityList.get(0).SalesRepEmail__c} = ${lead.CustomObjectEmail})
  1. Don’t use curly braces (= ${formal} = formal references) inside directives. Use $simple notation.
  2. I have not once seen code where it’s correct to simply use the first indexed Opportunity (.get(0)) . The Opportunity list must be treated as an arbitrarily ordered list. You should be targeting a specific Opportunity based on other characteristics, such as deliberately sorting the list by a Date field or checking other field values for the matching Opportunity.
michaelstancil
Level 3

@SanfordWhiteman Thanks for the pointers, you made me realize I needed another value to key off of.

 

 

#set( $lead.CustomObjectEmail = "CATCHALL@EMAIL.COM" )
#foreach( $Opportunity in $OpportunityList )
#if( $Opportunity.VARIABLETOUPDATEAGAINST.isNotEmpty )
  #set( $lead.CustomObjectEmail = $Opportunity.SalesRepEmail__c )
  #break
#end
#end

 

 

Jo_Pitts1
Level 10 - Community Advisor

@michaelstancil ,

this still won't work no matter HOW technically correct your code.. you can't update the lead from Velocity (hence why I didn't even get into to discussing coding with you).

 

I think you need a webhook to do this.  FlowBoost is probably a good option.

 

@SanfordWhiteman, can you see custom objects in FlowBoost?

 

Cheers

Jo

 

 

michaelstancil
Level 3

@Jo_Pitts1 so I've been trying to rework this based on limitation, and I've done more digging and found some various close-but-not-quite solutions from @SanfordWhiteman 

 

Regarding flowboost, if I can't set the value of a custom object via velocity, and given that these values are within the opportunity, how would I pass those to a webhook? Webhooks can't receive opportunity info, can they?

 

Perhaps this requires a new post, but is it possible to send a notification email within an email script token? Since the crux of this is the access level of opportunity vs. lead information, could I create an email script token that runs at the end of said consumer facing email that sends a notification containing that opportunity info to the relevant sales person, since all of those items are within the opportunity?

 

Assuming that was the case, my next thought would be to summarize the list of affected items by sales rep, and then sending them a notification email that has all of the affected items for the day. The only thing I'm struggling with (that I'm aware of) is that the DATEFIELDOBJECT__c within the opportunity is a YYYY-MM-DD HH:MM:SS, and I'd like to ignore the HH:MM:SS and just say "if date = today, count the items"

## Time Items
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Phoenix") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

## Filter Items
#set( $CustomList1 = [] )
#foreach( $Opp in $OpportunityList )
#if( $OpportunityList.DATEFIELDOBJECT__c.NOTSURE)
#set( $void = $CustomList1.add($Opp) )
#end
#end

## Display List of Items
#foreach( $Opp in $CustomList1 )
Name: ${OpportunityList.Name}
Phone: ${OpportunityList.Phone}
</br>
#end

 

 

michaelstancil
Level 3

@Jo_Pitts1 gotcha, let me take a look!

 

@SanfordWhiteman (and Jo) if it WAS possible, would the revised code be correct at least?

SanfordWhiteman
Level 10 - Community Moderator

More like

#set( $lead.CustomObjectEmail = "CATCHALL@EXAMPLE.COM" )
#foreach( $Opportunity in $OpportunityList )
#if( !$display.alt($Opportunity.VARIABLETOUPDATEAGAINST,"").isEmpty() )
  #set( $lead.CustomObjectEmail = $Opportunity.SalesRepEmail__c )
  #break
#end
#end

because you need to account for the field being either null or an empty string.

michaelstancil
Level 3

Gotcha - Thanks!

SanfordWhiteman
Level 10 - Community Moderator
You certainly can.
Jo_Pitts1
Level 10 - Community Advisor

Are you expecting this to update back into the database?

If so, that won't work.  Velocity doesn't write back to the Marketo DB.

Regards

michaelstancil
Level 3

That's exactly what I was hoping...as I was going to use that new field and perform a change data value. Are there any other ways around something like this?

Jo_Pitts1
Level 10 - Community Advisor

I'm a bit bewildered here.

Are you trying to update the Sales Rep email on the lead or on the opportunity?

What if they have more than one opportunity.

 

i.e. can you explain the use case wrt opportunities and leads please

michaelstancil
Level 3

Welcome to my world haha.

 

So we have Account and Sales owners, but because of how our system works they may get moved off to a variety of reasons and replaced with a catchall. Should that opportunity update to be valid again, the catch-all will remain on the account/sales level, but the in-opportunity fields will update with that correct info. 

 

It is very likely the sales reps will have multiple opportunities, so they would get multiple emails, one per unique opportunity (tied to a customer email, one opp per cust email)

 

The opportunity Owner (which does surface in the notification option) is there, but it's only their name. Is there some way to transform that field to an email?