How to create and trigger a delivery using js activity webapp / workflow CreateFromModel, PrepareFromId | Community
Skip to main content
david--garcia
Level 10
December 9, 2021
Solved

How to create and trigger a delivery using js activity webapp / workflow CreateFromModel, PrepareFromId

  • December 9, 2021
  • 3 replies
  • 3277 views

Hi All,

I am working on a preference centre with the aim of notifying users on profile changes so that these can then be approved or cancelled, normally, I would trigger a command from the webapp to start a workflow and submit a few variables to personalize a delivery and execute it, however, I want to test out an alternative way of triggering the notification but I am short in time to go deep into testing and finding out how it works.

 

How do you personalize, and execute a delivery on the fly using js activity? my goal is to execute it from the webapp, (under other circumstances if the client had a message centre, I would construct and trigger a real time event to message centre, but the client does not have this)

 

Here is what I have so far, but to put it sumply, I want to have a delivery template with some html and variables in it, then trigger the delivery from within the webapp.

 

 

 

 

var delivery = nms.delivery.create(); delivery.label="Delivery Test" delivery.scheduling.validationMode = "automatic" delivery.scheduling.delayed = 0 delivery.save() vars.deliveryId = delivery.id

 

 

 

 

Update 1

I have the following script, but I am facing an issue

 

 

 

 

var recipientId = 13241267; var template = "changesNotification"; var x = <delivery> <targets> <deliveryTarget> <targetPart exclusion='false' ignoreDeleteStatus='false'> <where> <condition expr={'@id=' + recipientId}/> </where> </targetPart> </deliveryTarget> </targets> </delivery>; var y = nms.delivery.CreateFromModel(template, x); var z = nms.delivery.create(y); z.scheduling.delayed = 0; z.scheduling.validationMode = "auto"; z.save(); nms.delivery.PrepareFromId(z.id);

 

 

 

 

 

 

Update 2

 

I've used the SubmitDelivery method and I still get the same error

 

 

var deliveryId = nms.delivery.SubmitDelivery("changesNotification", <delivery> <targets> <deliveryTarget> <targetPart exclusion='false' ignoreDeleteStatus='false'> <where> <condition expr="[@id] = 13246096"/> </where> </targetPart> </deliveryTarget> </targets> </delivery>);

 

 

 

 

Thanks

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 david--garcia

Update 3

 

Both scripts actually work, after double checking the configuration of my template, the target mapping had been set to nms:subscription rather than nms:recipient which is what the error code was pointing to, I can now sleep in peace.

 

 

3 replies

Manoj_Kumar
Community Advisor
Community Advisor
December 9, 2021

Hello @david--garcia 

 

A solution is posted here for personalized HTML and submit delivery method.

https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-standard/how-to-send-an-email-through-an-javascript/m-p/264599

 

Another way to do is by creating a workflow with external signal and then passing the dynamic variables to WF by postevent menthod.

 

Manoj  | https://themartech.pro
david--garcia
Level 10
December 9, 2021

Hey Manoj,

 

I've already tried and I get the same error, please see update 2, I am wondering why the audit log states attribute id unknown and to check the definition of the nms:subscription schema, could you please test both scripts on your side and let me know if you get the same error?

 

Manoj_Kumar
Community Advisor
Community Advisor
December 9, 2021

@david--garcia 

 

Trying chaging the condition to

 <condition expr="@id = 13246096"/>
Manoj  | https://themartech.pro
david--garcia
david--garciaAuthorAccepted solution
Level 10
December 9, 2021

Update 3

 

Both scripts actually work, after double checking the configuration of my template, the target mapping had been set to nms:subscription rather than nms:recipient which is what the error code was pointing to, I can now sleep in peace.