2

With the code (AMPscript) below I'm currently able to retrieve properties for a subscriber object, but I'm unable to retrieve the (Profile) Attributes. What am I missing?

Adding the "CreateDate" property item to the object array (AddObjectArrayItem(@rr,"Properties","CreatedDate")) and assigning it to the "@x" variable will display the subscriber's create date BUT if I try to add the "Attributes" property item to the object array (AddObjectArrayItem(@rr,"Properties","Attribues")), no subscriber record will be returned.

<!DOCTYPE html>
<html>
    <head></head>
    <body>
    %%[
    // find the subscriber
        VAR @sid, @mid, @rr, @sfp, @sub_rowset, @sub_row, @sk, @x

        SET @sid = subscriberid

        SET @mid = CreateObject("ClientID")
        SetObjectProperty(@mid,"ID","#####") /*mid removed for privacy*/

        SET @rr = CreateObject("RetrieveRequest")
        SetObjectProperty(@rr,"ObjectType","Subscriber")
        AddObjectArrayItem(@rr,"Properties","SubscriberKey")
        AddObjectArrayItem(@rr,"Properties","CreatedDate")
        AddObjectArrayItem(@rr,"ClientIDs",@mid)

        SET @sfp = CreateObject("SimpleFilterPart")
        SetObjectProperty(@sfp,"Property","ID")
        SetObjectProperty(@sfp,"SimpleOperator","equals")
        AddObjectArrayItem(@sfp,"Value",V(@sid))

        SetObjectProperty(@rr,"Filter",@sfp)

        SET @sub_rowset = InvokeRetrieve(@rr)

        IF ROWCOUNT(@sub_rowset) == 1 THEN
            SET @sub_row = ROW(@sub_rowset,1)
            SET @sk = FIELD(@sub_row,"SubscriberKey")
            SET @x = FIELD(@sub_row,"CreatedDate")

            OutputLine(CONCAT("SubscriberKey: ",V(@sk),"<br>"))
            OutputLine(CONCAT("StringValue: ",V(@x),"<br>"))
        ELSE
            // subscriber could not be found
            OutputLine(CONCAT("Unable to find the specified subscriber","<br>"))
        ENDIF
    ]%%
    </body>
</html>

Any help will be greatly appreciated!

1 Answer 1

3

I'm not sure why but adding the ID Property when retrieving the Subscriber object will return the custom Profile Attributes.

Add this to your request:

AddObjectArrayItem(@rr,"Properties","ID")

Then, you can loop through and do whatever you need with the key/value pairs like this:

SET @attributes = FIELD(@sub_row,"Attributes")

IF ROWCOUNT(@attributes) > 0 THEN
    OutputLine(Concat("<br /><br /><b>ATTRIBUTES:</b><br />"))
    FOR @i = 1 to ROWCOUNT(@attributes) DO
        SET @currentAttribute = Row(@attributes,@i)
        SET @name = Field(@currentAttribute,"Name")
        set @value = Field(@currentAttribute,"Value")
        OutputLine(Concat(@name,": ",@value,"<br />"))
    NEXT @i
ENDIF

I tested this using your posted code. The entire updated block is below:

<!DOCTYPE html>
<html>
    <head></head>
    <body>
    %%[
    // find the subscriber
        VAR @sid, @mid, @rr, @sfp, @sub_rowset, @sub_row, @sk, @x

        SET @sid = subscriberid

        SET @mid = CreateObject("ClientID")
        SetObjectProperty(@mid,"ID","######") /*mid removed for privacy*/

        SET @rr = CreateObject("RetrieveRequest")
        SetObjectProperty(@rr,"ObjectType","Subscriber")
        AddObjectArrayItem(@rr,"Properties","SubscriberKey")
        AddObjectArrayItem(@rr,"Properties","CreatedDate")
        AddObjectArrayItem(@rr,"Properties","ID")
        AddObjectArrayItem(@rr,"ClientIDs",@mid)

        SET @sfp = CreateObject("SimpleFilterPart")
        SetObjectProperty(@sfp,"Property","ID")
        SetObjectProperty(@sfp,"SimpleOperator","equals")
        AddObjectArrayItem(@sfp,"Value",V(@sid))

        SetObjectProperty(@rr,"Filter",@sfp)

        SET @sub_rowset = InvokeRetrieve(@rr)

        IF ROWCOUNT(@sub_rowset) == 1 THEN
            SET @sub_row = ROW(@sub_rowset,1)
            SET @sk = FIELD(@sub_row,"SubscriberKey")
            SET @x = FIELD(@sub_row,"CreatedDate")

            OutputLine(CONCAT("SubscriberKey: ",V(@sk),"<br />"))
            OutputLine(CONCAT("StringValue: ",V(@x),"<br />"))

            /* now print the attributes if they exist */
            SET @attributes = FIELD(@sub_row,"Attributes")

            IF ROWCOUNT(@attributes) > 0 THEN
                OutputLine(Concat("<br /><br /><b>ATTRIBUTES:</b><br />"))
                FOR @i = 1 to ROWCOUNT(@attributes) DO
                    SET @currentAttribute = Row(@attributes,@i)
                    SET @name = Field(@currentAttribute,"Name")
                    set @value = Field(@currentAttribute,"Value")
                    OutputLine(Concat(@name,": ",@value,"<br />"))
                NEXT @i
            ENDIF

        ELSE
            // subscriber could not be found
            OutputLine(CONCAT("Unable to find the specified subscriber","<br>"))
        ENDIF
    ]%%
    </body>
</html>

You must log in to answer this question.

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