How to add a personalized field dynamically during delivery run-time?

SriBhargav94-go

29-03-2019

Hello Folks,

I have a campaign workflow with an delivery in which content is coming from AEM with a placeholder <%= targetData.url %>. This will get value from the additional data that i have added in Query whenever workflow runs. But i have got the requirement to trigger the delivery directly from Delivery template instead of going with a workflow. When i am doing this, i am facing an error targetData not found, since there is no previous activity to get the data just like how it happens in case of workflow.

Is there any way to replace such field with let's say i can directly fetch this field in template from the blip icon Recipients -> URL. After selecting this i am getting a personalized field <%= recipient.url %> courtesy due to target mapping. If so, How can i replace <%= targetData.url %> with <%= recipient.url %> during run-time, can i use a typology rule for it? Please provide pointers.

PS: I understood that we can change the placeholder directly in AEM template to <%= recipient.url %> but we are not supposed to do that, instead we are trying possibilities from Campaign itself

Regards,

Sri Bhargav

Accepted Solutions (1)

Accepted Solutions (1)

geoffreyl240454

29-03-2019

Hello Sri,

I put this code into a typology rule and it seems to work properly:

// HTML version

var regExp = new RegExp('targetData', 'gi');

var existingHtml = delivery.content.html.source;

var newHtml = existingHtml.replace(regExp, 'recipient');

delivery.content.html.source = newHtml;

Best Regards,

Geoffrey LE GAC.

Answers (2)

Answers (2)

SriBhargav94-go

31-03-2019

It worked, i tried negative case like:

1. When word to replace is not found - No error thrown, i chosen Level as Info, instead of Error/Warning ​in the typology rule.

Thanks,

Sri Bhargav

SriBhargav94-go

30-03-2019

Thank You Geoffrey,

Will try this Approach, but can you please let me know if it still works, when there no such word found. Let's say i am searching for word target and if found replace it with word recipient. What if not found? Will it throw any error or i can able to configure the rule in such a way that Don't throw error, instead log warning.

Regards,

Sri Bhargav