WebApp collecting new email addresses, but only search/create on a single Recipient Folder

davidh2892249

03-08-2018

Hi There,

I am building a simple webApp whereby I'd like users to be able to submit their email address and it creates a new recipient record in a new recipient folder.

However, if the same email address is submitted more than once - it should not create another new recipient record.

To add to the complexity, I do not want any recipient records that sit in other recipient folders to be impacted.

I have a simple page where a text input is stored against a variable "emailEntered".

Then I am looking to use a script activity to write the data to the recipient schema.

var emailEntered = ctx.vars.emailEntered;

xtk.session.Write(<recipient xtkschema="nms:recipient" _operation="insertOrUpdate" _key="@email" email={emailEntered} folder-id="928454" />);

(folder-id 928454 being the id of the "new recipient folder").

I thought that the insertOrUpdate operation would help handle the potential of the same email address being entered multiple times, not creating multiple records.

However with this approach, if the email address exists against a record in the recipient schema (but in a different folder), it will update that old record and move it to the new folder. I do not want this, i do not want this webapp impacting existing recipient records that exist elsewhere in the system. I just want it to handle data submitted through this webapp. Essentially i'm looking for similar functionality to the "storage" activity where you can specify a search folder as part of the reconciliation and only search in that folder to see if a record exists or not already.

1541289_pastedImage_2.png

Any thoughts on this one?

Thanks all

David

ps. This is my WebApp structure

1541290_pastedImage_3.png

Accepted Solutions (0)

Answers (7)

Answers (7)

davidh2892249

10-08-2018

Hi Vipul,

Perhaps I'm not quite understanding, but I think my biggest challenge is how do I retrieve the recipient ID of the newly created recipient?

My WebApp has 1 input, which is stored against a variable (ctx.vars.emailEntered).

I can then use that variable to add as a new recipient using javascript activity:

var emailEntered = ctx.vars.emailEntered;

xtk.session.Write(<recipient xtkschema="nms:recipient" _operation="insertOrUpdate" _key="@email,folder/@id" email={emailEntered}>

  <folder _operation="none" name="Folder18"/>

</recipient>);

But then, how do I retrieve the recipient id of that newly created recipient? (whether it be to pass it as a variable to another workflow, or use a nms.delivery.QueueNotification and use it as part of the target condition).

I'm probably overcomplicating things, but if you can shed any light on this for me - that would be great.

I'm sure it's some pretty simple code, just something that I'm not aware of right now.

Thanks

David

Vapsy

Employee

10-08-2018

Hi David,

Why not have a workflow with an External signal (configured to receive recipient ID as a variable and also the folderID) and then connect it to activity that fetches this recipient and feeds to a continuous delivery.

Inside your webapp you just need to fire a xtk.workflow.PostEvent call and thats it.

Another possibility will be to fire a SOAP call to Message Center where in over the webapp you prepare the CTX for soap call and then send it over to Message Center. Your SOAP call will need all personalization information into the payload and hence makes your task a bit easier. Additionally, you can pass the recipientID into the external identifier attribute so that when the data comes back to marketing you can reconcile the information.

Regards,
Vipul

davidh2892249

09-08-2018

Hi J-Serge,

Was just looking for the specific code i'd need to identify the recently created record within the javascript.

The exact same code as mentioned above wasn't working in the absence of pre-loading / storage.

I've got around it with the below, but this is only feasible because the recipient folder in question is only getting new data added by this form and I am reconciling on email+folder id (_key="@email,folder/@id") as part of my xtk.session.Write javascript (so there should never be duplicate email addresses within this folder).

nms.delivery.QueueNotification("webappWelcome",

<delivery>

<targets>

  <deliveryTarget>

    <targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>

      <where>

        <condition expr={"@email = '"+ctx.vars.emailEntered+"'"} bool-operator="AND" />

        <condition expr="[folder/@id] = 928454"/>

      </where>

    </targetPart>

  </deliveryTarget>

</targets>

</delivery>)

Wonder if anyone can share an alternative way?

Thanks

David

Jean-Serge_Biro

MVP

09-08-2018

Hi David,

Both mechanisms work fine, whatever with Page activity or Page (compatibility v5) activity for automatic subscription with a delivery template defined in your nms:service record (see documentation example for double optin example: Use cases: web forms )

or for specific automated mail continuous deliveries, by using QueueNotification.

By the way, you can do with Javascript, but Update activity was still usable for your use case, we have the same for the company I work with.

Regards
J-Serge

davidh2892249

09-08-2018

Hi Vipul Raghav

Thanks, this worked perfectly.

var emailEntered = ctx.vars.emailEntered;

xtk.session.Write(<recipient xtkschema="nms:recipient" _operation="insertOrUpdate" _key="@email,folder/@id" email={emailEntered}>

  <folder _operation="none" name="Folder18"/>

</recipient>);

I wondered if you could help me with the final part of the puzzle.

I'd like to trigger an email to the newly created recipient.

I think this could be achieved in 2 ways:

1) Add them to a subscription that has a linked delivery template.

2) Use the nms.delivery.QueueNotification method to trigger the email.

I have a couple of working examples in the past, but they are slightly different.

1) For the subscription example I have, I use a javascript activity with this code:

nms.subscription.Subscribe("deliveryTemplateInternalName", ctx.recipient, false)

However, I appreciate this works as the webApp is using preloading - so can identify which recipient to add to the subscription service.

2) for the nms.delivery.QueueNotification previous example I have, I use a javascript activity with this code.

nms.delivery.QueueNotification("deliveryTemplateInternalName",

<delivery>

<targets>

  <deliveryTarget>

    <targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>

      <where>

        <condition expr={'@id ='+ ctx.recipient.@id}/>

      </where>

    </targetPart>

  </deliveryTarget>

</targets>

</delivery>)

This previous example is collecting new anonymous data (like my new webapp) but rather than storing the inputs against a variable (that is later written to the recipient schema through xtk.session.Write), the inputs are configured to be stored against recipient schema fields and then a storage activity is used to write the data.

Does the storage activity in advance of the above nms.delivery.QueueNotification javascript activity somehow give context so that the webapp knows which recipient the email should be triggered to?

Could anyone help advise how I can make my new webApp identify the newly created recipient record and either add to a subscription or trigger a delivery template (ideally examples of both would be amazing).

Thanks in advance

David

Vapsy

Employee

04-08-2018

Hi David,

You should use

xtk.session.Write(<recipient xtkschema="nms:recipient" _operation="insertOrUpdate" _key="@email,folder/@id" email="firstName1.lastName1@mymail.com" firstName="Vipul" lastName="Raghav">

  <folder _operation="none" name="nmsRootRecipient"/>

</recipient>);

Please do replace the folder internal name as per your requirement.

Regards,
Vipul