1

we are trying to create ower own preference center. When using the code below, the right lists etc are loaded, but the Update Button has no function yet and I do not know how to do it. Any recommendations ore ideas? I changed the MID and SubKey :-)

%%[

/* Get the Id of the account / Set @mid = "ID COMES HERE" / Get the key from the form */ Set @subKey = "KEY COMES HERE"

if Empty(@subKey) or @subKey == "" then SET @subKey = "[email protected]" endif

/* Create the subscriber's object */ set @subscriber = CreateObject( "Subscriber" ) SetObjectProperty( @subscriber, "EmailAddress", @subKey ) SetObjectProperty( @subscriber, "SubscriberKey", @subKey )

/* make sure the system is posting */ SET @isUpdate = RequestParameter("personal")

SET @save = "FALSE"

if Not Empty(@isUpdate) then

SET @save = "TRUE" /* get the attributes and checkBoxes */ SET @checkBoxes = RequestParameter("checkBoxList") SET @attributes = RequestParameter("attributes")

/* Create arrays from each of the lists / SET @checkArray = BuildRowSetFromString(@checkBoxes,"||") SET @attArray = BuildRowSetFromString(@attributes,"||") SET @attCount = RowCount(@attArray) SET @checkCount = RowCount(@checkArray) SET @display = "" SET @display2 = "" if @attCount > 0 then / iterate all of the elements */ FOR @i = 1 TO @attCount DO

 Set @attribute = Field(Row(@attArray, @i),1)

 Set @value = RequestParameter(@attribute)

 /* Create the Attribute */
 Set @att = CreateObject( "Attribute" )
 SetObjectProperty( @att, "Name", @attribute )
 SetObjectProperty( @att, "Value", @value )

 /* Set the attribute to the subscriber */
 AddObjectArrayItem( @subscriber, "Attributes", @att )

 /*
 Set @display = Concat(@display,@attribute, " = " , @value, " @@@ ")
 */
NEXT @i

endif

/* Set @display = Concat(@display," ---CHECK --- ") */

if @checkCount > 0 then /* iterate all of the elements */ FOR @i = 1 TO @checkCount DO

 set @values = ""

 Set @attribute = Field(Row(@checkArray, @i),1)

 Set @internalCheckArray = BuildRowSetFromString(@attribute,":")

 if RowCount(@internalCheckArray) > 1 then
  SET @checkName = Field(Row(@internalCheckArray, 1),1)

  SET @checkNumber = Field(Row(@internalCheckArray, 2),1)

  FOR @j = @checkNumber DOWNTO 1 DO

   Set @singleCheckName = Concat(@checkName,@j)
   Set @value = RequestParameter(@singleCheckName)

   IF not Empty(@value) then

    if(Empty(@values))then
     set @values = @value
    else
     set @values = Concat(@values, ",", @value )
    endif

   endif


  NEXT @j

  /* Create the Attribute */
  Set @apiName = Replace(@checkName,"-"," ")
  Set @att = CreateObject( "Attribute" )
  SetObjectProperty( @att, "Name", @apiName )
  SetObjectProperty( @att, "Value", @values )

  /* Set the attribute to the subscriber */
  AddObjectArrayItem( @subscriber, "Attributes", @att )

  /*
  Set @display = Concat(@display,@apiName, " = " , @values, " @@@ ")
  */
 endif
NEXT @i

endif endif

/* Did the user pressed the subscriptions submit button */ if RequestParameter("subscription") == 1 then

SET @save = "TRUE" /* request paramter from List A */ Set @theListA = RequestParameter("ListsA") Set @array = BuildRowSetFromString(@theListA, '|')

for @r = 1 to Rowcount(@array) do

Set @configRow = Row(@array,@r)
Set @configkey = Field(@configRow,1)

Set @value = RequestParameter(@configkey)

if Empty(@value) then

 set @subscription = CreateObject("SubscriberList")
 SetObjectProperty( @subscription, "ID", @configkey )
 SetObjectProperty( @subscription, "IDSpecified", "true" )
 SetObjectProperty( @subscription, "Status", "Unsubscribed" )
 SetObjectProperty( @subscription, "StatusSpecified", "true" )
 AddObjectArrayItem( @subscriber, "Lists", @subscription )
else
 set @subscription = CreateObject("SubscriberList")
 SetObjectProperty( @subscription, "ID", @configkey )
 SetObjectProperty( @subscription, "IDSpecified", "true" )
 SetObjectProperty( @subscription, "Status", "Active" )
 SetObjectProperty( @subscription, "StatusSpecified", "true" )
 AddObjectArrayItem( @subscriber, "Lists", @subscription )
endif

next @r

/* request paramter from List U */ Set @theListU = RequestParameter("ListsU") Set @array = BuildRowSetFromString(@theListU, '|')

for @r = 1 to Rowcount(@array) do

Set @configRow = Row(@array,@r)
Set @configkey = Field(@configRow,1)

Set @value = RequestParameter(@configkey)

if @value == "Active" then

 set @subscription = CreateObject("SubscriberList")
 SetObjectProperty( @subscription, "ID", @configkey )
 SetObjectProperty( @subscription, "IDSpecified", "true" )
 SetObjectProperty( @subscription, "Status", "Active" )
 SetObjectProperty( @subscription, "Action", "create" )
 AddObjectArrayItem( @subscriber, "Lists", @subscription )
endif

next @r endif

/* Did the user pressed the unsub all submit button */ if RequestParameter("subscriptionALL") == 1 then

SET @save = "TRUE" if RequestParameter("UnsubAll") == "true" then SetObjectProperty( @subscriber, "Status", "Unsubscribed" ) else SET @error = "True" set @message = "Please Select One of the Options" endif endif

/* SET @display3 = "" / / Did the user change their preferernces */ if RequestParameter("preference") == 1 then

SET @save = "TRUE" Set @ppr = RequestParameter("preferences") Set @array = BuildRowSetFromString(@ppr, '|') /* SET @display3 = Concat(@array,"@@@@@@@@@") */ for @r = 1 to Rowcount(@array) do

Set @configRow = Row(@array,@r)
Set @configkey = Field(@configRow,1)

Set @value = RequestParameter(@configkey)

 if @configKey == "EmailTypePreference" then

  if @value == "true" then
   SetObjectProperty( @subscriber, "EmailTypePreference", "HTML" )
  else
   SetObjectProperty( @subscriber, "EmailTypePreference", "TEXT" )
  endif

 else

  if @value == "true" then
   Set @value = "True"
  else
   Set @value = "False"
  endif

  set @pref = CreateObject( "Attribute" )
  SetObjectProperty( @pref, "Name", @configkey )
  SetObjectProperty( @pref, "Value", @value )
  AddObjectArrayItem( @subscriber, "Attributes", @pref )

 endIf

next @r endif

IF @save == "TRUE" then /* change the last modify date */ SET @theTime = Format(Now(), "MM/dd/yyyy") set @LastModify = CreateObject( "Attribute" ) SetObjectProperty( @LastModify, "Name", "Last Modify" ) SetObjectProperty( @LastModify, "Value", @theTime ) AddObjectArrayItem( @subscriber, "Attributes", @LastModify )

/* Update the Subscriber If we have to */ var @createOpts, @saveOpt

/* Create the save option / set @saveOpt = CreateObject("SaveOption") SetObjectProperty( @saveOpt, "SaveAction", "UpdateAdd" ) SetObjectProperty( @saveOpt, "PropertyName", "" )

/* Specify the Update option */ set @createOpts = CreateObject("CreateOptions") AddObjectArrayItem( @createOpts, "SaveOptions", @saveOpt )

/* Update the subscriber */ set @createStatusCode = InvokeCreate( @subscriber, @createErrDesc, @createErrNo, @createOpts )

/* If we failed to create the subscriber, output the information as the top level error */ if @createStatusCode != "OK" then Redirect("http://%%microsite_base_url[default]3891541[/default]%%") else SET @TheWorks = 'true' endif endif

]%%

My Subscriptions

Tell us which emails you would like to subscribe to here. Be sure to click the update button in this section!

Available Publications %%[ /* Find Out the status of the subscribers */ SET @rr4 = CreateObject("RetrieveRequest") SetObjectProperty(@rr4,"ObjectType","ListSubscriber") AddObjectArrayItem(@rr4, "Properties", "Status") AddObjectArrayItem(@rr4, "Properties", "ListID") /* Make sure that the list is public */ SET @sfp2 = CreateObject("SimpleFilterPart") SetObjectProperty(@sfp2,"Property","SubscriberKey") SetObjectProperty(@sfp2,"SimpleOperator","equals") AddObjectArrayItem(@sfp2,"Value",@subKey) /* set the filter to the request */ SetObjectProperty(@rr4,"Filter",@sfp2) SET @listStatus = InvokeRetrieve(@rr4, @status) /* Create the Request for the list */ SET @rr3 = CreateObject("RetrieveRequest") SetObjectProperty(@rr3,"ObjectType","List") AddObjectArrayItem(@rr3, "Properties", "ListName") AddObjectArrayItem(@rr3, "Properties", "Type") AddObjectArrayItem(@rr3, "Properties", "Description") AddObjectArrayItem(@rr3, "Properties", "ID") /* Make sure that the list is public */ SET @sfp2 = CreateObject("SimpleFilterPart") SetObjectProperty(@sfp2,"Property","Type") SetObjectProperty(@sfp2,"SimpleOperator","equals") AddObjectArrayItem(@sfp2,"Value","public") /* Make sure that the list is not a publication list */ SET @sfp3 = CreateObject("SimpleFilterPart") SetObjectProperty(@sfp3,"Property","ListClassification") SetObjectProperty(@sfp3,"SimpleOperator","equals") AddObjectArrayItem(@sfp3,"Value","ExactTargetList") /* set the complex filter */ Set @cf1 = CreateObject("ComplexFilterPart") SetObjectProperty(@cf1,"LeftOperand",@sfp2) SetObjectProperty(@cf1,"RightOperand",@sfp3) SetObjectProperty(@cf1,"LogicalOperator","AND") /* set the filter to the request */ SetObjectProperty(@rr3,"Filter",@cf1) SET @atts = InvokeRetrieve(@rr3, @status) /* String to store all the list ids */ SET @ListsA = "" SET @ListsU = "" Set @lA = 1 Set @lU = 1 /* make sure that there are list */ IF RowCount(@atts) > 0 THEN /* for all the list */ FOR @c = 1 TO RowCount(@atts) DO /* get each of the rows */ SET @lis = Row(@atts,@c) /* get the necesary variables */ SET @lis_name = Field(@lis,'ListName') SET @lis_ID = Field(@lis,'ID') SET @lis_des = Field(@lis,'Description') Set @printed = false /* Find the status of the public list */ IF RowCount(@listStatus) > 0 THEN /* for all the status of the list */ FOR @d = 1 TO RowCount(@listStatus) DO SET @lisStat = Row(@listStatus,@d) SET @lisStat_id = Field(@lisStat,'ListID') SET @lis_status = Field(@lisStat,'Status') if @lisStat_id == @lis_ID and @lis_status == 'Active' then ]%% %%=v(@lis_name)=%%
%%=v(@lis_des)=%%

%%[ /* create the array of Active list ids */ if @lA == 1 then SET @ListsA = @lis_ID SET @lA = 2 else SET @ListsA = Concat(@ListsA, "|" , @lis_ID) endif Set @printed = true elseif @lisStat_id == @lis_ID and @lis_status == 'Unsubscribed' then ]%% %%=v(@lis_name)=%%
%%=v(@lis_des)=%%

%%[ /* create the array of Active list ids */ if @lA == 1 then SET @ListsA = @lis_ID SET @lA = 2 else SET @ListsA = Concat(@ListsA, "|" , @lis_ID) endif Set @printed = true endif NEXT @d ENDIF IF @printed == false then ]%% %%=v(@lis_name)=%%
%%=v(@lis_des)=%%
%%[ /* create the array of Non Active list ids */ if @lD== 1 then SET @ListsU = @lis_ID SET @lD = 2 else SET @ListsU = Concat(@ListsU, "|" , @lis_ID) endif endif NEXT @c endif ]%% Update Unsubscribe from ALL I no longer wish to receive any publications. Please unsubscribe me from all current AND future publications. (Note, if you are open to trying out new publications we produce in the future, you should NOT check this box, but should just uncheck the ones listed in Available Publications. It is a legal thing.)
Update ^ Top of Page

My Preferences

Indicate your email preferences here. Once you have made changes to your information, click the Update button.

<div id="preferenceBody">
 <form id="preference" action="%%= RequestParameter('PAGEURL') =%%" method="post">

  %%[
    /* List that will store all the preferences */
    var @preferences
    SET @preferences = "EmailTypePreference"

    /* Get all the subscriber attributes */
    SET @rr2 = CreateObject("RetrieveRequest")
    SetObjectProperty(@rr2,"ObjectType","Subscriber")
    AddObjectArrayItem(@rr2, "Properties", "ID")
    AddObjectArrayItem(@rr2, "Properties", "EmailTypePreference")
    AddObjectArrayItem(@rr2, "Properties", "EmailAddress")
    AddObjectArrayItem(@rr2, "Properties", "SubscriberKey")
    AddObjectArrayItem(@rr2, "Properties", "Status")

    /* Create a filter be the subscriber Id */
    SET @sfp2 = CreateObject("SimpleFilterPart")
    SetObjectProperty(@sfp2,"Property","SubscriberKey")
    SetObjectProperty(@sfp2,"SimpleOperator","equals")
    AddObjectArrayItem(@sfp2,"Value",@subKey)

    /* invoke the Retrieve Call */
    SetObjectProperty(@rr2,"Filter",@sfp2)
    SET @atts = InvokeRetrieve(@rr2,@status)

    /* Make a list of the Preferences */
    IF RowCount(@atts) > 0 THEN

     SET @subAtts = Field(Row(@atts,1),"Attributes")
     SET @pereference = Field(Row(@atts,1),"EmailTypePreference")
     ]%%
      <input type="checkbox" name="EmailTypePreference" value="true" %%[ if @pereference == "HTML" then ]%% checked="true" %%[endif]%%> HTML Emails <br>
      <small> When possible, send e-mail newsletters as HTML instead of plain text.</small>
     %%[
     Set @p = 1
     /* for all the attributes make sure if the values are true or False */
     FOR @c = 1 TO RowCount(@subAtts) DO
      SET @att = Row(@subAtts,@c)
      SET @att_name = Field(@att,'Name')
      SET @att_val = Field(@att,'Value')


      /* save the corresponding values to an array */
      IF @att_val == "true" or @att_val == "false" then

       SET @preferences = Concat(@att_name, "|" , @preferences)


       ]%%
        <input type="checkbox" name="%%=v(@att_name)=%%" value="true" %%[ IF @att_val == "true" then ]%% checked="true" %%[ ENDIF ]%%> %%=v(@att_name)=%% <br>

       %%[
      ENDIF

     NEXT @c
    ENDIF

    ]%%
  <input type="hidden" name="preferences" id="preferences" value="%%=v(@preferences)=%%">
  <button type="submit" value="1" name="preference" style="margin-top: 20px;"> Update </button>
 </form>

</div>

<div id="sectionFooter">
 <a href="#TheTop">^ Top of Page</a><br>
</div>

6
  • have you tried removing the spaces around %%= RequestParameter('PAGEURL') =%% and using %%=RequestParameter('PAGEURL')=%% instead? Commented Aug 10, 2018 at 13:46
  • Thx, tried it now, but it does still not work Commented Aug 10, 2018 at 13:58
  • Have you verified that the URL fills in correctly? I would right click the submit button and use 'inspect element' (for Google Chrome) or the equivalent inside your browser of choice and verify that the action contains the URL Commented Aug 10, 2018 at 14:00
  • Hm, it seems not to work in the right way. Commented Aug 10, 2018 at 14:10
  • After clicking it shows this <form id="subscription" action="cloud.business.XXX.com/preferences" method="post"> <div id="dynamicSubscription"> Commented Aug 10, 2018 at 14:20

1 Answer 1

2

@isUpdate will always be evaluated as false as there is no personal field on your page:

 SET @isUpdate = RequestParameter("personal")

I think you meant to set this to the value of the hidden field submitted by the form. Try replacing the above line with this one:

 SET @isUpdate = RequestParameter("preferences")

You must log in to answer this question.

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