Hi Team,
I want to implement the subscription service to leads table and I have changed accordingly in the schema also but I am getting the following error when i calling the subscribe method. Kindly help me with this.
Error Screenshot:
Configuration in a schema.
<srcSchema _cs="NmxSubscribers (nmx)" created="2018-12-14 06:52:19.316Z" createdBy-id="0"
desc="Subscribers of Nissan mexico" entitySchema="xtk:srcSchema" img="nms:subscribe.png"
implements="xtk:persist" label="NmxSubscribers" labelSingular="NmxSubscribers"
lastModified="2018-12-14 07:39:30.445Z" mappingType="sql" md5="87FA6502025F1D6DEA7808B4E8CF0921"
modifiedBy-id="0" name="nmxSubscribers" namespace="nmx" xtkschema="xtk:srcSchema">
<createdBy _cs="Jitendra Thota (jitendra)"/>
<modifiedBy _cs="Jitendra Thota (jitendra)"/>
<element desc="Subscribers of Nissan mexico" img="nms:subscribe.png" label="NmxSubscribers"
labelSingular="NmxSubscribers" name="nmxSubscribers" pkgStatus="never">
<key internal="true" name="nmxSubscribers">
<keyfield xlink="service"/>
<keyfield xlink="lead"/>
</key>
<dbindex name="confirmationId">
<keyfield xpath="@confirmationId"/>
</dbindex>
<dbindex name="lead">
<keyfield xlink="lead"/>
<keyfield xpath="@addressSpecific"/>
</dbindex>
<compute-string expr="[service/@label] + ' / ' + lead"/>
<attribute default="GetDate()" desc="Creation date" label="Creation date" name="created"
type="datetime"/>
<attribute desc="Subscription valid until" label="Expiration date" name="expirationDate"
sqlname="tsExpiration" type="date"/>
<attribute dataPolicy="none" desc="Address to use for the subscription" label="Specific Address"
name="addressSpecific" template="xtk:common:email"/>
<!--<attribute desc="Email format type" enum="all:lead.recipient.emailFormat" label="Email format"
name="emailFormat" type="byte"/>-->
<attribute default="0" desc="Email format type" enum="nms:recipient:messageFormat"
label="Email format" name="emailFormat" type="byte"/>
<attribute expr="Coalesce(@addressSpecific, IfEquals(ToString([service/@type]),'0',[lead/@email],IfEquals(ToString([service/@type]),'1',[lead/@mobilePhone],IfEquals(ToString([service/@type]),'2',[lead/@homePhone],[lead/@officePhone]))))"
label="Address" name="address" type="string"/>
<!-- needed to send confirmations -->
<attribute name="deleteStatus" template="xtk:common:deleteStatus"/>
<attribute advanced="true" desc="Identifier used to group confirmation messages into a single delivery (this is not a foreign key)"
label="Confirmation Id" name="confirmationId" type="long"/>
<element integrity="neutral" label="Service" name="service" revIntegrity="own"
revLabel="Leads scriptions" target="nms:service" type="link"/>
<element integrity="neutral" label="Leads" name="lead" revIntegrity="own" revLabel="Subscriptions"
target="all:lead" type="link"/>
</element>
<methods>
<method name="LeadsSubscribe" static="true">
<help>Subscribe/unsubscribe selected recipients to a list of Information Services.</help>
<parameters>
<param desc="Leads list" name="leadList" type="DOMElement"/>
<param desc="List of services" name="serviceList" type="DOMElement"/>
<param desc="Subscribe/Unsubscribe Leads" name="subscribe" type="boolean"/>
<param desc="Send a confirmation message" name="sendConfirmation" type="DOMElement"/>
<param desc="List of confirmation IDs" inout="out" name="confirmationIds"
type="DOMElement"/>
</parameters>
</method>
<method name="SendConfirmation" static="true">
<help>Send a confirmation message</help>
<parameters>
<param desc="Internal name of associated delivery template" name="internalName"
type="string"/>
<param desc="Confirmation message Id" name="confirmationId" type="string"/>
</parameters>
</method>
<method name="Subscribe" static="true" >
<help>Create or update a lead subscription to an Information Service</help>
<parameters>
<param desc="List of Information Service names (comma separated)" name="serviceName"
type="string"/>
<param desc="Leads to register and optionally to create" name="lead" type="DOMElement"/>
<param desc="Create recipient if it does not exist" name="create" type="boolean"/>
</parameters>
<example language="javascript">
<programlisting>var lead = {lead: {_key: "email", email: "john.smith@example.com"}}
nmx.nmxSubscribers.Subscribe("SVC1", lead, false)</programlisting>
</example>
</method>
<method name="Unsubscribe" static="true">
<help>Unsubscribes a recipient from an Information Service</help>
<parameters>
<param desc="List of Information Service names (comma separated)" name="serviceName"
type="string"/>
<param desc="Leads" name="lead" type="DOMElement"/>
</parameters>
<example language="javascript">
<programlisting>var lead = {lead: {_key: "email", email: "john.smith@example.com"}}
nmx.nmxSubscribers.Unsubscribe("SVC1", lead)</programlisting>
</example>
</method>
<method name="DeleteService" static="true">
<help>Delete selected Information Services</help>
<parameters>
<param desc="Service identifier" inout="in" name="id" type="string"/>
</parameters>
</method>
</methods>
</srcSchema>
Java script code:
//Update visitor
if(ctx.vars.visitorId.length() > 0)
{
ctx.lead.visitor.@firstName = ctx.lead.@firstName
ctx.lead.visitor.@lastName = ctx.lead.@lastName
ctx.lead.visitor.@recipientId = ctx.lead.@id
ctx.lead.visitor.@email = ctx.lead.@email
ctx.lead.visitor.@referrerId = decryptString(ctx.vars.referrerId)
ctx.lead.visitor.@deliveryId = decryptString(ctx.vars.deliveryId)
ctx.lead.visitor.@id = decryptString(ctx.vars.visitorId)
ctx.lead.visitor.@xtkschema = "nms:visitor"
ctx.lead.visitor.@_operation = "update"
ctx.lead.visitor.@_key="@email"
xtk.session.Write(ctx.lead.visitor)
}
// Subscribe recipient recipient
delete ctx.lead.visitor
var lead =ctx.lead;
//alert("2nd script values ::"+ctx.lead.@email);
lead.@_key="@email"
delete lead.@blackList_init
delete lead.@xtkschema
nmx.nmxSubscribers.Subscribe(ctx.vars.serviceName,lead,false)
// Send confirmation
nms.delivery.QueueNotification("confirmation",
<delivery>
<targets>
<deliveryTarget>
<targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>
<where>
<condition expr={'@email ='+ ctx.lead.@email}/>
</where>
</targetPart>
</deliveryTarget>
</targets>
</delivery>)
Regards
Jitendra