0

We have a use case where we’re pulling in a url from Salesforce CRM which contains the entire A tag. We’re looking to use Substring but can’t pull in the end of the URL before the quote.

  • “” target=” won’t work,
  • " target=" produces a quote at the end
  • We’ve tried single quotes: ‘ “ target= “ ‘ with no luck.

Any ideas on how to extract the url below between the quotes to render in a call to action button in an email?

Request__c:Site_URL__c = <a href=”https://mycervello.com/?requestid=a0Y2i000003Upy0BBB&signature=%2HH2RWnDntoo3CmmyAySPy1qNvwoiTuTrubI8ovMv7aU%2D” target="_blank">Click here for the form</a>

Ampscript:

SET @emailLinklong= [Request__c:Site_URL__c]
SET @DP_StringBegin = " target="
SET @emailLink = Substring(@emailLinklong,10,Subtract(IndexOf(@emailLinklong,@DP_StringBegin),1))

2 Answers 2

2

This is kind of hacky, but should work if the input matches the syntax of your example:

SET @emailLinklong= [Request__c:Site_URL__c]
SET @rowSet = BuildRowsetFromString(@emailLinklong, "”")
SET @row = Row(@rowSet, 2)
SET @emailLink = Field(@row, 1)

How does this work?

BuildRowsetFromString() breaks your string into 3 different parts delimited by the character

Row Number  |  RowSet
------------|---------------------------------------------------------------------------
    1       |  <a href=
    2       |  https://mycervello.com/?requestid=a0Y2i000003Upy0BBB&signature=%2HH2RWnDntoo3CmmyAySPy1qNvwoiTuTrubI8ovMv7aU%2D
    3       |  target="_blank">Click here for the form</a>

The resulting data is of the rowset data type, so you need to select the second row by using the Row() function and then pull it's contents with Field (this is not a rowset with multiple named fields, so using 1 as the parameter gets you the value you need).

1
  • Thank you Rafal, after experimenting by rendering the variable we were able to use the code and change the 1 to an 11 at the end, the quote wasn't the issue after all - sorry for not testing fully before posting: SET @emailLink = Substring(@emailLinklong,10,Subtract(IndexOf(@emailLinklong,@DP_StringBegin),11)) We are capturing your suggestion for future use as we'll probably have a use case that will work, very cool design. Thank you for your time.
    – TimZ
    Jul 27 at 22:47
-2

The replace function could work.

var @Link
SET @Link = replace(@emailLink, "” target=","")

https://ampscript.guide/replace/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.