I tried UpdateDE with this code but it sent the same "unique code" when I did a test send to multiple emails"
%%[ var @customerCode, @codeDataExtension, @availableCodes, @randomIndex

set @codeDataExtension = "Codes_test" /* Replace with your data extension name */

/* Retrieve available codes from the data extension */ set @availableCodes = LookupRows(@codeDataExtension, "Status", "Available")

if RowCount(@availableCodes) > 0 then /* Randomly select a code from the available codes / set @randomIndex = Random(1, RowCount(@availableCodes)) set @customerCode = Field(Row(@availableCodes, @randomIndex), "Code") / Update the code's availability in the data extension to mark it as assigned */ UpdateDE(@codeDataExtension, 1, "Code", @customerCode, "Status", "Assigned")

else /* No available codes, handle the situation accordingly */ set @customerCode = "No available codes" endif ]%%

I have a DE that's contains a bunch of unique codes, is it possible to select codes in bunches (1 per email send) and then mark each code as 'used' once that particular code has been used in an email send (We cant send the same code twice). I thought using something like a AMPscript lookup function could work, and I tried the 'update data' function would but that doesn't work for emails..?

I've done something similar but that was in a bulk send where we had subscriber key and the codes in the same DE. This time we wont know which subscribers are to be sent a unique code until they complete an 'action'.

We'll have a file import that contains Subscriber keys and other info (not the codes) that will be delivered into SFMC via a file drop every 15 minutes (capturing people that completed 'said action'). We don't want to avoid manually assigning codes and manually sending out emails every 15 mins. So Im hoping that there was some AMPscript (Or anything other ideas reall) I could use...?


  • 2
    This is exactly what the ClaimRow function is for: ampscript.guide/claimrow
    – zuzannamj
    May 18, 2023 at 6:30
  • Thankyou, Ill give that a go now
    – user120467
    May 18, 2023 at 23:54
  • 1
    In addition to what has been said, "updateData" will not work in email but updateDE does :)
    – Ted Chan
    May 19, 2023 at 1:29
  • I tried update DE but it was sending the same unique code out on when i was testing to multiple emails. AMPscript i used in updated post above
    – user120467
    May 19, 2023 at 3:48
  • There seems to be some missing asterisk for your comment block? And is there a reason why they have to be randomized before assigning the code?
    – Ted Chan
    May 19, 2023 at 5:32

1 Answer 1


You should try to use the ClaimRow function. https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/claimrow.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .