I am working at a code for a resubscribe for a custom unsubscribe centre that will update the Active Status back in Marketing Cloud & also updates a custom object in Salesforce; the update in Salesforce work fine & it also works the code when I hardcode the MID.

As we work with brand specific subscribers we need these updates to occur for specific MIDs. I have uploaded these in a non sendable data extension in MArketing Cloud & I am trying to pull them via amp script.

My code for the resubscribe piece is below:

    SET @SubscriberKey = RequestParameter("SubscriberKey")
    SET @Email = RequestParameter("Email")
    SET @SalesforceID = Substring(@SubscriberKey, 0, 15)
    SET @MKTId = RequestParameter("MKTId") /* Id of the Marketing Cloud Consent Object found in the previous page */

UpdateSingleSalesforceObject("Marketing_Consent__c", @MKTId,
                                     "Source__c","Resubscribed via RCH Unsubscribed Centre",
                                     "Opt_In__c", "True",
                                     "Reason__c", "I have decided to resubscribe",
                                     "Assumed_Opt_in__c", "True"


/* Create and populate a RetrieveRequest */
SET @retrieveRequest = CreateObject("RetrieveRequest")
SetObjectProperty(@retrieveRequest, "ObjectType", "DataExtensionObject[Accounts to Reconsent]")

AddObjectArrayItem(@retrieveRequest, "Properties","Business unit name")
AddObjectArrayItem(@retrieveRequest, "Properties","MID")

/* Execute the Retrieve */
SET @Members = InvokeRetrieve(@retrieveRequest)

SET @MembersCount = RowCount(@Members)
/* Iterate over the data */

FOR @i = 1 to @MembersCount DO
    SET @currentSub = Row(@Members, @i)
    SET @properties = Field(@currentSub,"Properties")
    Set @numofProperties = ROWCOUNT(@properties)

FOR @j = 1 to @numofProperties DO

    SET @currentProp = Row(@properties, @j)
    Set @Field1= FIELD(@currentProp ,"Name") 
    Set @Field2= FIELD(@currentProp ,"Value") 

/*Update the unsubscribe from all list*/  
SET @ll_sub = CreateObject("Subscriber")

SetObjectProperty(@ll_sub,"EmailAddress", @Email)
SetObjectProperty(@ll_sub,"SubscriberKey", @SubscriberKey)

SET @client = CreateObject("ClientID")
SetObjectProperty(@client, "ID", @Field2)
SetObjectProperty(@client, "IDSpecified", "true")
SetObjectProperty(@ll_sub, "Client", @client)

Set @options = CreateObject("UpdateOptions")
Set @save = CreateObject("SaveOption")
AddObjectArrayItem(@options,"SaveOptions", @save)

/* Here is where we actually update the Subscriber object */
Set @update_sub = InvokeUpdate(@ll_sub, @update_sub_status, @update_sub_errorcode, @options)

NEXT @i]%%

My Subscriber has:
Key: %%=v(@SubscriberKey)=%%
Email: %%=v(@Email)=%%
Marketing Consent: %%=v(@MKTId)=%%

I have used this documentation:


and this piece of code pulls all the MIDs for which i need the resubscribe to happen.

Any guidance is appreciated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.