1

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)

SetObjectProperty(@ll_sub,"Status","Active")
Set @options = CreateObject("UpdateOptions")
Set @save = CreateObject("SaveOption")
SetObjectProperty(@save,"SaveAction","UpdateAdd")
SetObjectProperty(@save,"PropertyName","Status")
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 @j
NEXT @i]%%

My Subscriber has:
<br>
Key: %%=v(@SubscriberKey)=%%
<br>
Email: %%=v(@Email)=%%
<br>
Marketing Consent: %%=v(@MKTId)=%%
<br>
THANKS FOR RESUBSCRIBING! 

I have used this documentation:

https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/retrieveRows.htm

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

Any guidance is appreciated.

Giulietta

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.