I have a AMPScript snippet where I am retrieving a variable from a returned row-set and then using the same variable as the value for a simple filter. The name of the variable is @listID.

If I don't use this variable, then the snippet works fine. I am unable to determine the issue. I have a hunch that it has something to do with variable scope and the for loop.

I would appreciate any inputs.

I have put the code snippet for reference as well.

IF @listCount > 0 THEN
  for @i = 1 to @listCount do 
    Set @listname = Field(Row(@lists, @i),"ListName")
    Set @ListID = Field(Row(@lists, @i),"ID")

    set @rr1 = CreateObject("RetrieveRequest")

    set @sfp1 = CreateObject("SimpleFilterPart")

    set @sfp2 = CreateObject("SimpleFilterPart")

    set @cfp = CreateObject("ComplexFilterPart")
    SetObjectProperty(@cfp,"LeftOperand", @sfp1)
    SetObjectProperty(@cfp,"LogicalOperator", "AND")
    SetObjectProperty(@cfp,"RightOperand", @sfp2)


    set @ListSubObj = InvokeRetrieve(@rr1,@rrStatus,@rrRequestID)

    if rowCount(@ListSubObj) > 0 then 
      var @row
      set @row = row(@ListSubObj, 1)
      set @liststatus = field(@row,'Status')

      if @liststatus != "Active" then
        @checked = false
        @checked = true*/



Thanks - Monomit

  • 1
    I'm not sure if this is the latest version of your code (or if parts were intentionally omitted for brevity), but there are a few syntax issues: (1) the @checked variable identifiers are missing their preceding set keywords, (2) the closing next @i is missing from the for statement, (3) the closing endif for the outermost if statement is missing, and (4) there's an orphaned */ comment delimiter. Other than that, could provide a little more details surrounding the issue? Are you seeing... an error message? Unexpected/incorrect values being assigned? Code blocks not being executed?
    – Mark G
    May 31, 2019 at 4:21
  • I would recommend including the rowset you are pulling listid as well. Is there ever a case that ListID could be empty/null? (E.g. Nullable field). I would output the variables inside your for loop on a Cloudpage to check that the values are being correctly passed. Also, where is the @sid coming from? and is it actually the SubscriberID or is it the SubscriberKey (as it is assigned in the API call)? They are not synonymous and are completely different values. May 31, 2019 at 11:57
  • Thanks to both of you. The code is in a Cloudpage. I have added a portion of the code. sid is the subscriber key and is available. I checked the listids, they are coming with values. The checked portion is commented in the original code block, I messed up while copy pasting. It should have a set but it's commented. The error is 500 error when I am trying to run the Cloudpage. I am trying to retrieve a list of publists and then for each of the lists trying to find out if a subscriber is active and then render the checkbox as checked or unchecked. Jun 1, 2019 at 17:02

1 Answer 1


Formatting the variable to a string resolved the issue. AddObjectArrayItem(@sfp2,"Value",FormatNumber(@listID,"G"))

You must log in to answer this question.

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