How to add additional functionality to your custom schema in Adobe Campaign Classic?

adobe-campaign-query-def-variants

During implementation, you will have to create custom methods to perform required actions on the schema. These custom methods can either be implemented for an out of the box schema or for your customer schema in Adobe Campaign.

Today will see the steps to add your own custom methods in Adobe Campaign. Let us implement a custom method to implement the below use case.

Implementation Use-case: E-commerce Website

Your company has planned a huge sale tomorrow. As part of the sale you have provided 1000 credits to all the customers on your e-commerce website. The customers can only use this credit tomorrow. Tomorrow EOD the credits needs to be reset to zero. (For simplicity we will assume that all customer only have 1000 credits on the day of the sale and this number has to be reset to zero at EOD.Imagine this to be the official inaugration of the e-commerce website)

The customer credits are stored in the column “credits” in the recipient extended schema.

Let us start coding the implementation,

Step 1: Implementation to reset the credit of selected recipient

The implementation of the method needs to be in the JS file that you create in this step.Create the JS, recipientCreditReset.js and add the function “setCredit” to it.

The format of the function name should be strictly followed.

<schema-namespace>_<schema-name>_<method-name>

For our “setCredit” method, you can use the below code

function nms_recipient_setCredit(id) {
  var myRecipient = nms.recipient.load(id);
   myRecipient.credit=0;
   myRecipient.save();
}

Step 2: Declare the method in the custom/out of the box schema

Open the recipient schema and add the below method to it. The method’s JavaScript implementation is provided in the file recipientCreditReset.js under the namespace “cus”.

The name of the method is “setCredit”.

This is a static method, so you do not have to invoke an object before it can be used.

This method takes one parameter “id”, which is the primary key of of the recipient whose record is going to be updated.

Now, when this method is called, campaign is going to go to the JS file 
recipientCreditReset.js in “cus” namespace and will look for the definition of the “setCredit” method.

<methods>
 <method library=cus:recipientCreditReset.js name="setCredit" static="true">
    <parameters>
        <param desc="Recipient Credit Reset" name="id" type="long"
    </parameters>
 <method>
</methods>

Step 3: Call the custom method from a JS activity/workflow

In this step you will call the custom method using a JS activity.

//Select the required recipient
var query = xtk.queryDef.create(
    <queryDef schema="nms:recipient" operation="select">
       <select>
         <node expr="@email"/>
         <node expr="@credits"/>
		 <node expr="@id"/>
       </select>
       <where>
         <condition expr="@lastName='Shetty'"/>
		 <condition expr="@firstName='Prajwal'"/>
       </where>
       <orderBy>
         <node expr="@email" sortDesc="false"/> 
       </orderBy>    
   </queryDef>
   )
   
//Execute the query
var res = query.ExecuteQuery()

for each (var w in res.recipient) {
	//for each returned recipient, reset their credit
	nms.recipient.setCredit(w.@id);
}

Now, you have successfully implemented the e-commerce company use-case.

Just add a scheduler in front of the workflow and set it to execute at EOD. Adobe Campaign will take care of your task of resetting the customer’s credits to zero at EOD. You can have a good night sleep.

Hope this helps.

error: Content is protected !!