Convert User's ID to User's Name in Email Script

Valerie_Armstro
Level 10 - Champion Alumni

Convert User's ID to User's Name in Email Script

Hello Community,

There is a lookup field (to the Users object) on a Salesforce Custom Object that I need to utilize in an upcoming campaign.  In the email, I would want to User's Full Name to appear.

Assuming I need an email script to do this, I've tried various ways to get the Name (not the ID) to pop in, but have been unsuccessful.

Here is the working script that returns the User ID:

#set( $psm_name = "Onboarding Specialist" )

#if( ${PSM__cList.get(0).PSM_Owner__c} )

#set( $psm_name = ${PSM__cList.get(0).PSM_Owner__c} )

#end

$psm_name

Is there a simpler way than having a bunch of if/then statements that would need to be maintained as the Onboarding team changes?

Thanks!

9 REPLIES 9
Scott_McKeighe2
Level 5

Re: Convert User's ID to User's Name in Email Script

Are you trying to evaluate whether a custom object field value matches another field?

Also, have you tried setting the PSM Owner value as a variable before evaluating it with an #if? Something like:

#set ( $a = ${PSM__cList.get(0).PSM_Owner__c} )

#if ( !$a )

Display a default value if A is null

#else

$a

#end

We just had a huge overhaul of some of our assets that utilized Velocity and custom SFDC objects, and that was (essentially) the method we had to follow.

Valerie_Armstro
Level 10 - Champion Alumni

Re: Convert User's ID to User's Name in Email Script

Hi Scott,

I am attempting to retrieve the full name of the user who is assigned to the onboarding record. Onboarding is a custom object we have in SFDC. On the Onboarding object, there is a lookup field (related to the User object) called Onboarding Specialist.

When I use the email script I put in my initial question, it returns the SFDC User ID instead of the name of the User.

Example: pastedImage_7.png

Ideally, I would like the script to lookup the User ID and return that user's full name (e.g. Valerie Armstrong instead of 005C0000006nTBAIA2) without having a bunch of if/then statements that would need to be managed as new onboarders come onto the team.  Would the method you provided work in such a case?

Thanks!

Casey_Grimes
Level 10

Re: Convert User's ID to User's Name in Email Script

Hi Valerie,

Theoretically yes, you could just do a large number of if/then statements, but if you plan on using this on any sort of regular basis I'd just make a quick Marketo custom object holding the SFDC User IDs and their corresponding values and reference that.

Valerie_Armstro
Level 10 - Champion Alumni

Re: Convert User's ID to User's Name in Email Script

Hi Courtney Grimes​ - Have you done something similar? Is there a way I can set up this Marketo Custom Object so that it is always up-to-date when new users are added and other are deactivated?

Casey_Grimes
Level 10

Re: Convert User's ID to User's Name in Email Script

Hi Valerie,

...kind of? The real pain point is removing users that are deactivated; right now there's no non-API way to remove Salesforce-linked custom objects, even if they are deleted on the SFDC side. Currently I've been routing around this by doing calculations for the most recent matching value, but that's far from ideal. However, if you're just matching values for your Salesforce users, it may not even be an issue.

Scott_McKeighe2
Level 5

Re: Convert User's ID to User's Name in Email Script

I think in this case it'd be best to map your custom SFDC object out to a custom Marketo object as Courtney suggested. I'm not sure what the syntax would be in Velocity to grab the display/text value of a SFDC lookup. This thread in the Salesforce Dev community might be worth looking at, though, as a starting point.

An alternative would be to push the name of the Op Specialist into another field/string that you can target via Velocity, and then have the user's account link stored separately.  In that case, the method above would work and display a name value.

Valerie_Armstro
Level 10 - Champion Alumni

Re: Convert User's ID to User's Name in Email Script

Hi Scott McKeighen​,

Is there any documentation on how to map a SFDC Custom Object to a Marketo Custom Object?  How would one go about setting up a connection between the two so that they are constantly in sync?

Thanks!

Scott_McKeighe2
Level 5

Re: Convert User's ID to User's Name in Email Script

Hey Valerie Armstrong

I'm purely speculating, but it looks like you could theoretically achieve this with a background process that originates in Salesforce and pushes to Marketo via REST -- Marketo REST APIs: Custom Objects » Marketo Developers

This example from the Salesforce StackExchange community touches on the notion of calling from Salesforce into Marketo -- Making REST API calls from Salesforce to Marketo - Salesforce Stack Exchange. The example is specific to leads being created, but I'm sure you could repurpose the methods outlined to update existing records whenever their Onboarding Specialist changes.

Hope that points you in the right direction!

Anonymous
Not applicable

Re: Convert User's ID to User's Name in Email Script

I think it is doable with 'webhooks'. You can write a web hook service that will fetch the user name from SFDC from the user id. And return that when the webhook is called from Marketo.

Also webhooks might be better solution than email scripting. Because using email scripting, all you can do it 'show' the user name in that email. Thus in every such email, you will have to code email script. While using webhook, you can populate a field in Marketo with the user name and use it in anyplace you want.

Hope this helps

Rajesh Talele