Example of JS nms.subscription.RecipientSubscribe() | Community
Skip to main content
Florian_Courgey
Level 4
November 29, 2018
Solved

Example of JS nms.subscription.RecipientSubscribe()

  • November 29, 2018
  • 7 replies
  • 5283 views

Hi,

I couldn't find any working example of the following method:

XML confirmationIds = RecipientSubscribe (      XML          recipientList,      XML          serviceList,      Boolean      subscribe,      XML          sendConfirmation )

Could you please show how it works?

I tried, without the success, the following:

var serviceXml = {service: {_key: "name", name: 'myServiceInternalName'}};

var recipientXml = {recipient: {_key: "email", email: 'my-recipient@yopmail.com'}};

var sendConfirmationXml = {sendConfirmation:{sendConfirmation:'true'}}; // what to use here???

var subscribe = true;

var confirmationIds = nms.subscription.RecipientSubscribe (

    recipientXml,

    serviceXml,

    subscribe,

    sendConfirmationXml

);

logInfo(confirmationIds);

Thank you

Florian

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jonathon_wodnicki

Hi,

Use this, apologies for the xml:

  nms.subscription.RecipientSubscribe (

    <choiceList selectAll="false">

        <key value="snarayen@adobe.com"/>

        <where>

            <condition expr="@email = 'snarayen@adobe.com'"/>

        </where>

    </choiceList>,

    <entityList selectAll="false">

        <key value="ceoTips"/>

        <where>

            <condition expr="@name = 'ceoTips'"/>

        </where>

    </entityList>,

    true,

    <empty>false</empty>

  );

You have access to the source code?

Thanks,

-Jon

7 replies

Jonathon_wodnicki
Community Advisor
Community Advisor
January 4, 2019

Hi,

That param can be left empty. If you want to send confirmations, use nms.subscription.SendConfirmation().

Recipient and services forms both stub out that param and instead send a 2nd call to that action.

Thanks,

-Jon

Florian_Courgey
Level 4
January 7, 2019

Hi Jon,

I tried to leave the last argument empty, but it doesn't work:

nms.subscription.RecipientSubscribe(recipientList, serviceList, subscribe);

It gives the error

01/07/2019 2:12:25 PM js SCR-160012 JavaScript: error while evaluating script 'WKF407/js'.

01/07/2019 2:12:25 PM js Missing argument 'sendConfirmation' for method 'RecipientSubscribe' of schema 'nms:subscription'.

I also tried the following, which doesn't work:

var sendConfirmation = ''; // cannot convert the value to an XML document

var sendConfirmation = null; // cannot convert the value to an XML document

var sendConfirmation = {}; // does nothing

var sendConfirmation = {sendConfirmation:{$:true}}; // puts the workflow in a hanging state (Automatically resuming workflow (number of consecutive times: 1))

Finally, I looked for any reference of "RecipientSubscribe(" in the AC7-8864 source code, but I couldn't find any.

You got any idea?

Thanks

Jonathon_wodnicki
Community Advisor
Jonathon_wodnickiCommunity AdvisorAccepted solution
Community Advisor
January 7, 2019

Hi,

Use this, apologies for the xml:

  nms.subscription.RecipientSubscribe (

    <choiceList selectAll="false">

        <key value="snarayen@adobe.com"/>

        <where>

            <condition expr="@email = 'snarayen@adobe.com'"/>

        </where>

    </choiceList>,

    <entityList selectAll="false">

        <key value="ceoTips"/>

        <where>

            <condition expr="@name = 'ceoTips'"/>

        </where>

    </entityList>,

    true,

    <empty>false</empty>

  );

You have access to the source code?

Thanks,

-Jon

Florian_Courgey
Level 4
January 22, 2019

Thanks, it's still not working but I'll have a second look

Source code can be downloaded on the support platform, from your Download Center > Build Neolane v6.1 nlserver6-8864-x86_64_rh7.rpm (8864)

adobe-campaign-rpm-file-download-center.jpg

Which contains some .xml and .js files, i.e. Find files with Notepad++:

adobe-campaign-find-source-code.jpg

Source: Access to Adobe Campaign Source Code

Jonathon_wodnicki
Community Advisor
Community Advisor
January 22, 2019

Oh I thought you meant the source code, cpp files. Most of those objects can be exported out of the instance per normal, some of them like non-specific db functions can only be read from the install dirs. What was the issue with the call I pasted?

Florian_Courgey
Level 4
March 5, 2019

Hi wodnicki,

The issue was that the subscription was not created. There was no error raised, but nothing happened.

It turned out using the @name of the service doesn't work. We had to use the @id. So first we convert the service name to a service id, then we use your XML.

This is what we ended up doing:

var recipientEmail = "henry.gallagher@yopmail.com";

var serviceName = "ceoTips";

var subscribe = true;

var sendConfirmation = true;

// get service id

var query = NLWS.xtkQueryDef.create({queryDef: {

  schema: "nms:service", operation: "get",

    select: { node: {expr: "@id"} },

    where: { condition: {expr: "@name='"+serviceName+"'"} },

}});

var serviceId = query.ExecuteQuery().$id;

// recipient query

var recipientList = {choiceList:{

  where: { condition: { expr: "@email = '"+recipientEmail+"'" } },

}}

// service query

var serviceList = entityList = {entityList:{

  key:{ value: serviceId }

}}

// call

var confirmationIds = nms.subscription.RecipientSubscribe (  

  recipientList, serviceList,

  subscribe, {empty: sendConfirmation}

);

logInfo('confirmationIds', confirmationIds); // DOMElement

logInfo('confirmationIds', confirmationIds.toString()); // 1:DM11|13605

logInfo('confirmationIds', confirmationIds.toXMLString(true)); // <elemConfirmationIds>1:DM11|13605</elemConfirmationIds>

Which seems overkill just to programmatically subscribe a recipient with the confirmation email... But it is needed in our case for a custom SOAP call.

Thank you

Florian

david--garcia
Level 10
December 28, 2022

Here is another variant

 

var recipients = <recipientlist> <where> <condition expr="@id IN '1234,2345,3456,4567,5678'"/> </where> </recipientlist>; var services = <service> <key value="111"/> <key value="222"/> <key value="333"/> </service>; var ids = nms.subscription.RecipientSubscribe(recipients, services, true, <setOfService sendConfirmation="false"/>); logInfo(ids.toXMLString());