Accessing the Lead ID from Velocity

Update 2018-12-06: This new post has code to get the Lead ID and additional fields, so it supersedes the snippet here.

Community user PL points out that the person’s Marketo ID (that oh-so-useful field for building links ’n’ such) isn't available in the Script Editor tree.

The workaround I gave him will work for any instance:

#set( $lead.Id = $convert.toInteger($mktmail.id.replaceAll("-.*${esc.d}","")) )