0

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")
    SetObjectProperty(@rr1,"ObjectType","ListSubscriber")
    AddObjectArrayItem(@rr1,"Properties","ListID")
    AddObjectAttayItem(@rr1,"Properties","Status")

    set @sfp1 = CreateObject("SimpleFilterPart")
    SetObjectProperty(@sfp1,"Property","SubscriberKey") 
    SetObjectProperty(@sfp1,"SimpleOperator","equals")
    AddObjectArrayItem(@sfp1,"Value",@sid)

    set @sfp2 = CreateObject("SimpleFilterPart")
    SetObjectProperty(@sfp2,"Property","ListID")
    SetObjectProperty(@sfp2,"SimpleOperator","equals")
    AddObjectArrayItem(@sfp2,"Value",@listID)

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

    SetObjectProperty(@rr1,"Filter",@cfp)

    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
      else
        @checked = true*/
      endif

    endif   

]%%

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 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. – Gortonington May 31 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. – Monomit Bhowmik Jun 1 at 17:02
0

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

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.