1

One of my clients are looking to bring a photo of a group in their email. This photo depends on the value of the group that is mentioned in a data extension.

I have written the amp script for this & looks like the amp script evaluates correctly the Key referenced in the ContentBlockbyKey by it fails when I do the send preview. I do have the content block with that specific key that matches the group value.

Please see the print screens attached. Script I wrote is below:

%%[ var @firstname,@group


SET @firstname=[First_Name]

SET @rows=LookupOrderedRows('FirstNamesDe2',0,'GroupID desc','ContactID',ContactID)
SET @rowcount=RowCount(@rows)

if @rowcount>0 then

for @i=1 to @rowcount do 
set @row=row(@rows,@i)
set @firstname=field(@row,"First_Name")
set @group=field(@row,"GroupID")]%%
%%=ContentBlockbyKey(@group)=%%
%%[next @i
endif
]%%

<br>
%%=v(@firstname)=%%
<br>
%%=v(@group)=%%
<br>

Any idea is appreciated.

Giuliettaenter image description here

enter image description here

enter image description here

2

ContentBlockbyKey() works to retrieve a Content Block element. But from the image you've shared you are referring to an Image element. I've only ever used ContentBlockByKey() on a HTML Content Block - so question if it works on retrieving an Image.

Try to create a Content Block (HTML) component and save the Content Block with 'GroupABC' Customer Key. Inside the content block you can place your image.

It should then be able to retrieve the Content Block using the ContentBlockByKey() function. You appear to be calling the correct GroupID as GroupABC is listed in the Error result

Try to also eliminate the reset of your AMPScript lookup by simply calling in the email:

%%=ContentBlockByKey('GroupABC')=%%

See if that retrieves the block.

Alternatively, check where the content blocks are stored - are they under Shared Content or Local?

  • 2
    If it is an image you are trying to call (not in a content block), the function you want is ContentImageByKey() - developer.salesforce.com/docs/… – Gortonington Oct 4 '18 at 13:02
  • thanks Gortonington. I tried it before but for some reason I wasn't able to get it working. After some tweaks I managed to achieve what I need using the following script: (..) SET @firstname=[First_Name] SET @defaultphoto='autumnFALL' SET @rows=LookupOrderedRows('FirstNamesDe2',0,'GroupID desc','ContactID',ContactID) SET @rowcount=RowCount(@rows) if @rowcount>0 then for @i=1 to @rowcount do set @row=row(@rows,@i) set @firstname=field(@row,"First_Name") set @group=field(@row,"GroupID")]%% %%=ContentImageByKey(@group,@defaultphoto)=%% %%[next @i endif ]%% – Giulietta Oct 4 '18 at 13:44

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.