Adobe Campaign services: Here is a handy script to opt in/out a recipient from all subscription services within Adobe Campaign through a JavaScript activity. This utility is particularly useful when managing large-scale opt-in/opt-out logic for recipients in workflows, preference centers, or automated campaigns.
The script includes four functions:
optInAll(recipient)
– Subscribes a recipient to all active services.optOutAll(recipient)
– Unsubscribes a recipient from all active services.optinService(recipient, serviceName)
– Subscribes a recipient to a specific service.optoutService(recipient, serviceName)
– Unsubscribes a recipient from a specific service.
Each function takes the recipient in XML format (e.g., <recipient @id="123"/>
) and interacts with Adobe Campaign’s nms:subscription
module using built-in JavaScript APIs.
Use this script within a JavaScript activity inside your workflow to dynamically manage service subscriptions based on business rules or user preferences.
loadLibrary("/nl/core/shared/nl.js");
NL.require("/nl/core/shared/xtk.js");
/***********************************************************************
Purpose: Opts the recipient in to all services
Input: recipient in xml form eg <recipient @id="123"/>
Returns: nothing
**********************************************************************/
var optInAll = function(recipient){
var query = xtk.queryDef.create(<queryDef schema='nms:service' operation='select'>
<select>
<node expr='@name'/>
</select>
<where>
<condition expr = "[folder/@id]<> 0 " />
<condition expr = "[@id]<>0" />
</where>
</queryDef>);
var services = query.ExecuteQuery();
for each(var service in services){
nms.subscription.Subscribe(service.@name, recipient, false);
}
}
/***********************************************************************
Purpose: Opts the recipient out of all services
Input: recipient in xml form eg <recipient @id="123"/>
Returns: nothing
**********************************************************************/
var optOutAll = function(recipient){
var query = xtk.queryDef.create(<queryDef schema='nms:service' operation='select'>
<select>
<node expr='@name'/>
</select>
<where>
<condition expr = "[folder/@id]<> 0 " />
<condition expr = "[@id]<>0" />
</where>
</queryDef>);
var services = query.ExecuteQuery();
for each(var service in services){
nms.subscription.Unsubscribe(service.@name, recipient);
}
}
/***********************************************************************
Purpose: Opts the recipient in to particular services
Input: recipient in xml form eg <recipient @id="123"/>
Returns: nothing
***********************************************************************/
var optinService = function(recipient, serviceName){
nms.subscription.Subscribe(serviceName, recipient, false);
}
/**********************************************************************
Purpose: Opts the recipient out of particular services
Input: recipient in xml form eg <recipient @id="123"/>
Returns: nothing
**********************************************************************/
var optoutService = function(recipient, serviceName){
nms.subscription.Unsubscribe(serviceName, recipient);
}
Use Case Examples to programmatically setting Adobe Campaign services
- Automatically opt users in to services after registration.
- Allow users to fully unsubscribe from all communications via a preference center.
- Enable dynamic subscription toggling based on user behavior or workflows.
Important Notes
- Ensure the services you’re subscribing/unsubscribing to/from exist and are active.
- Wrap this logic in proper error handling when implementing in production.
- For GDPR compliance, log all subscription changes with timestamps and purpose if needed.
(Visited 812 times, 1 visits today)