0

I need to add a subscriber to a list particularly the All Subscriber list, for cloudpagesUrl to work since it returns a broken link if the subscriber is not in the all subscriber list. I already tested and it works if I add the subscriber in the list.

Now the thing is, is there any way for me to add the subscriber to the list using AMPscript/SSJS. I tried some SSJS snippets but it returns me an Error

'Function is not available in sendable content'

I already tried the following

1.)

<script runat="server">    
Platform.Load("core","1.1.1");

var subkey = "abc123";
var email = "foo@bar.com"
var prox = new Script.Util.WSProxy();
var sub = {
    SubscriberKey: subkey,
    EmailAddress: email,
    Lists: [{
        ID: '52',
        Status: 'Active'
    }]
};
var options = { 
    SaveOptions: [{
      PropertyName: "*",
      SaveAction: "UpdateAdd"
    }]
};
var resp = prox.createItem("Subscriber", sub, options); 
Write("Response: " + Stringify(resp));

2.)

<script runat=server>
  Platform.Load("core","1");
  var myList = List.Init("ListExternalKey");
  var status = myList.Subscribers.Add("test@example.com");
  Write(status);
</script>

3.)

    var @ll_statusMsg

var @listName set @listName = "All Subscriber"

var @rr SET @rr = CreateObject("RetrieveRequest") 

SetObjectProperty(@rr, "ObjectType", "List")
 AddObjectArrayItem(@rr,"Properties","ListName") 
 AddObjectArrayItem(@rr,"Properties","ID")

var @sfp SET @sfp = CreateObject("SimpleFilterPart")
 SetObjectProperty(@sfp, "Property", "ListName")
 SetObjectProperty(@sfp, "SimpleOperator", "equals")
 AddObjectArrayItem(@sfp, "Value",@listName)
 SetObjectProperty(@rr, "Filter", @sfp) 

var @Sub SET @Sub = InvokeRetrieve(@rr) 

var @ListID  Set @ListID = Field(Row(@Sub,1),"ID")

var @ll_sub SET @ll_sub = CreateObject("Subscriber")
SetObjectProperty(@ll_sub, "EmailAddress", "testEmail")
SetObjectProperty(@ll_sub, "SubscriberKey", "AA032912BJK021")


var @subscription set @subscription = CreateObject("SubscriberList")
SetObjectProperty( @subscription, "ID",@ListID)
SetObjectProperty( @subscription, "IDSpecified", "true" )
SetObjectProperty( @subscription, "Status", "Active" )
SetObjectProperty( @subscription, "StatusSpecified", "true" )
AddObjectArrayItem( @ll_sub, "Lists", @subscription )

var @ll_statusCode SET @ll_statusCode = InvokeUpdate(@ll_sub, @ll_statusMsg, @errorCode)

IF @ll_statusCode != "OK" THEN
    RaiseError(@ll_statusMsg, 0, @ll_statusCode, @errorCode)
ENDIF

nothing seems to work. any advice will do.

This is how I use my CloudpagesUrl

%%[

var @url set @url = CloudPagesURl(@cloudpageId,'multipleParameters',@valueOfParameters)

var @shortUrl
//Used an api to make @url shorter  

]%%
 Click %%=RedirectTo(@shortUrl)=%% to view details
6
  • The error is self explanatory. Some functions are only to be used in LandingPages.. Check out this answer for adding a subscriber to a list using AMPScript: salesforce.stackexchange.com/questions/57310/… – Rachid Mamai Nov 26 '19 at 10:57
  • Tried and also throwing me an. CreateObject Function is not valid in content. This function is only allowed in non sendable content. Function: CreateObject("RetrieveRequest") – imajmdf Nov 26 '19 at 11:53
  • It makes sense. Why don't you try to address the problem differently? I mean by fixing the CloudPagesURL problem. Are you using your CloudPagesURL inside of an href? Are you wrapping it inside of a RedirectTo()? Id you don't mind, add some code on how are you using CloudPagesURL.. – Rachid Mamai Nov 26 '19 at 13:14
  • @RachidMamai the only way that I can find for cloudpagesUrl to work is if the subscriber is added in the All Subscriber list found it here salesforce.stackexchange.com/questions/209217/…. if you have other way to fix the issue of using cloudPagesUrl in sms message. Please advise. That is the reason why I was looking for a way to insert a subscriber in a list in the SMS Message – imajmdf Nov 26 '19 at 14:03
  • Oh yeah, I see. I don't have a workaround to be honest. Hope someone else can help.. – Rachid Mamai Nov 26 '19 at 15:12
1

It looks like you are trying to add a subscriber to the All Subscriber list in an email send. If you're sending from a data extension and the subscriber doesn't already exist in All Subscribers, Marketing Cloud will automatically add the subscriber to All Subscribers at send time. If you're not adding to All Subscribers, see below.

I'm not sure what your CloudPage is trying to do, but it sounds like it needs to read data off of a list (not the All Subscribers list). You'll need to do two things:

  1. At send time use UpsertDE to write to a data extension. Then run a scheduled automation and use Data Extract, File Transfer, and Import (into your list).
  2. On your CloudPage, use the SSJS to add the subscriber to the list with parameters passed from a link click in the email.

This accomplishes two things (1) if the contact doesn't click the link in the email they will be added to your list automatically and (2) if the contact does click the link, they will be added to the subscriber list from your CloudPage.

2
  • 1
    "If you're sending from a data extension and the subscriber doesn't already exist in All Subscribers, Marketing Cloud will automatically add the subscriber to All Subscribers at send time" @jacksonchen, how come this is not happening on our side is it because the entry source of our journey is salesforce data? – imajmdf Nov 27 '19 at 1:44
  • It is because you are using an SMS environment and that statement is only for Email Sends. SMS will only add into Contacts, not All Subscribers – Gortonington Dec 1 '19 at 12:06
0

You could try using HTTPPost() AMPscript function (I have not verified in SMS environment, but I have heard of others utilizing it in MobileConnect) to a Code Resource page that then contains your WSProxy to update the subscriber to the list/AllSubs you are looking to add into.

Keep in mind though, this is then sending an API in every single sms you are sending, which could delay each send, potentially timing it out. So I would ensure this is low volume/frequency before any implementation and I would only use this as a temporary solution while you work on something a bit more elegant and future-proof.

e.g. in the SMS use: HTTPPost("https://www.myCodeResource.com","text/html","",@PostStatus,"SubscriberKey",@SubKey,"EmailAddress",@EmailAddress)

then in your code resource use:

<script runat="server">    
Platform.Load("core","1.1.1");

var subkey = requestparameter("SubscriberKey");
var email = requestparameter("EmailAddress");
var prox = new Script.Util.WSProxy();
var sub = {
    SubscriberKey: subkey,
    EmailAddress: email,
    Lists: [{
        ID: '52',
        Status: 'Active'
    }]
};
var options = { 
    SaveOptions: [{
      PropertyName: "*",
      SaveAction: "UpdateAdd"
    }]
};
var resp = prox.createItem("Subscriber", sub, options); 
Write("Response: " + Stringify(resp));
</script>

The benefit to using a code resource for this is that I do believe it won't cost you a super message each time the page is called.

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.