How to Create a Triggered Send for an On-Your-Behalf Account Via AMPscript

From $1

    Doc-Wiki-BannerHK.png

    (Click the banner to go to the related Docs.Code.ExactTarget.com page.)

    This document contains conceptual information regarding the conceptual and procedural information on creating a triggered send for an On-Your-Behalf account via AMPscript. 

    Prerequisites

    You should possess a working familiarity with AMPscript in order to use this sample AMPscript code and modify it for your own use. You must also have an Enterprise account to use this AMPscript sample.

    Why Use AMPscript to Create a Triggered Send for an On-Your-Behalf Account

    Using AMPscript to create a triggered send for an On-Your-Behalf account allows an administrator to create the overall interaction while retaining the customization options available to an On-Your-Behalf user. You can use a consistent call and structure with your triggered sends and spread them out over several On-Your-Behalf accounts.

    Procedures

    Use the AMPscript shown below as a model of your triggered send. Note that you must set the Channel Member ID to the ID of the On-Your-Behalf account at the end of the AMPscript example.

    Sample AMPscript

    VAR @sub, @attr, @list, @statusCode, @statusMsg, @subKey, @errorCode
    
    SET @subKey = RequestParameter("EmailAddress")
    SET @sub = CreateObject("Subscriber")
    
    IF NOT EMPTY(@subKey) THEN     SetObjectProperty(@sub, "SubscriberKey", @subKey)
    ENDIF
    SetObjectProperty(@sub, "EmailAddress", RequestParameter("EmailAddress"))
    
    IF NOT IsNull(RequestParameter("PreferredStore")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "PreferredStore")
        SetObjectProperty(@attr, "Value", RequestParameter("PreferredStore"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    
        var @PriceZone
        SET @PriceZone = LookUp("store", "price_zone_key", "store_key", RequestParameter("PreferredStore"))
    
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "PriceZone")
        SetObjectProperty(@attr, "Value", @PriceZone)
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("First Name")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "First Name")
        SetObjectProperty(@attr, "Value", RequestParameter("First Name"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("Middle Initial")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "Middle Initial")
        SetObjectProperty(@attr, "Value", RequestParameter("Middle Initial"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("Last Name")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "Last Name")
        SetObjectProperty(@attr, "Value", RequestParameter("Last Name"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("Company Name")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "Company Name")
        SetObjectProperty(@attr, "Value", RequestParameter("Company Name"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("Address")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "Address")
        SetObjectProperty(@attr, "Value", RequestParameter("Address"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
     IF NOT IsNull(RequestParameter("Address 2")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "Address 2")
        SetObjectProperty(@attr, "Value", RequestParameter("Address 2"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("State")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "State")
        SetObjectProperty(@attr, "Value", RequestParameter("State"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("City")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "City")
        SetObjectProperty(@attr, "Value", RequestParameter("City"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("Zip")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "Zip")
        SetObjectProperty(@attr, "Value", RequestParameter("Zip"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    IF NOT IsNull(RequestParameter("Phone Number")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "Phone Number")
        SetObjectProperty(@attr, "Value", RequestParameter("Phone Number"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    SET @attr = CreateObject("Attribute")
    SetObjectProperty(@attr, "Name", "Events")
    IF NOT IsNull(RequestParameter("Events")) THEN
        SetObjectProperty(@attr, "Value", "Y")
    ELSE
        SetObjectProperty(@attr, "Value", "N")
    ENDIF
    AddObjectArrayItem(@sub, "Attributes", @attr)
    
    SET @attr = CreateObject("Attribute")
    SetObjectProperty(@attr, "Name", "News")
    IF NOT IsNull(RequestParameter("News")) THEN
        SetObjectProperty(@attr, "Value", "Y")
    ELSE
        SetObjectProperty(@attr, "Value", "N")
    ELSE
    AddObjectArrayItem(@sub, "Attributes", @attr)
    
    IF NOT IsNull(RequestParameter("HowReceived")) THEN
        SET @attr = CreateObject("Attribute")
        SetObjectProperty(@attr, "Name", "How Received")
        SetObjectProperty(@attr, "Value", RequestParameter("HowReceived"))
        AddObjectArrayItem(@sub, "Attributes", @attr)
    ENDIF
    
    SET @attr = CreateObject("Attribute")
    SetObjectProperty(@attr, "Name", "ChannelMemberID")
    SetObjectProperty(@attr, "Value", "INSERT NUMBER HERE")
    AddObjectArrayItem(@sub, "Attributes", @attr)
    
    SET @attr = CreateObject("Attribute")
    SetObjectProperty(@attr, "Name", "date_added")
    SetObjectProperty(@attr, "Value", Format(Now(),"M/d/yyyy"))
    AddObjectArrayItem(@sub, "Attributes", @attr)
    
    SET @list = CreateObject("SubscriberList")
    SetObjectProperty(@list, "Status", "Active")
    SetObjectProperty(@list, "ID", "INSERT NUMBER HERE")
    SetObjectProperty(@list, "Action", "create")
    AddObjectArrayItem(@sub, "Lists", @list)
    
    SET @statusCode = InvokeCreate(@sub, @statusMsg, @errorCode)
    
    IF @statusCode != "OK" THEN
        RaiseError(@statusMsg, 0, @statusCode, @errorCode)
    
    ELSE
    
    VAR @ts, @tsDef, @ts_sub, @ts_attr, @tsctr, @ts_subkey, @ts_statusCode, @ts_statusMsg, @owner, @client
    
    SET @ts = CreateObject("TriggeredSend")
    SET @tsDef = CreateObject("TriggeredSendDefinition")
    SET @ts_subkey = RequestParameter("EmailAddress")
    
    SetObjectProperty(@tsDef, "CustomerKey", "4466")
    SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
    
    SET @ts_sub = CreateObject("Subscriber")
    SetObjectProperty(@ts_sub, "EmailAddress", RequestParameter("EmailAddress"))
    
    IF NOT EMPTY(@ts_subkey) THEN
        SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)
    ELSE
        SetObjectProperty(@ts_sub, "SubscriberKey", RequestParameter("EmailAddress"))
    ENDIF
    
    SET @owner = CreateObject("Owner") 
    SET @client = CreateObject("ClientID") 
    
    SetObjectProperty(@client, "ID", "INSERT NUMBER HERE")
    SetObjectProperty(@owner, "Client", @client)
    SetObjectProperty(@ts_sub, "Owner", @owner)
    
    AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
    SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)
    
    IF @ts_statusCode != "OK" THEN
        RaiseError(concat(@ts_statusMsg,@ts_subkey,@ts), 0, @ts_statusCode, @errorCode)
    ENDIF
    
    ENDIF

     

     


    This page was last updated by Ryan Williams on Tue, 10 Jan 2012 13:26:45 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 15510 backwards:
       
    Tags: (Edit tags)
    • No tags
     
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin