Birthday campaign json not working | Community
Skip to main content
Level 2
January 20, 2025
Solved

Birthday campaign json not working

  • January 20, 2025
  • 2 replies
  • 707 views

Please find the below script which is not working whereas the code seems proper 

{% let age1=0 %}
{% let datedifference = dateDiff(toDateTimeOnly(currentTimeInMillis()), toDateTimeOnly(profile.person.birthDate))%}
{% let age1 = absolute(toInt(roundUp(datedifference/365)))%}

{%#if age1=20.0 or age1=30.0 or age1=40.0 or age1=50.0 %} {
"content_id": "content1",
"param1": "{%= titleCase(profile.person.name.firstName)%}",
"param2": "{{age1}}"
}
{%else %} {
"content_id": "content2",
"param1": "{{age1}}"

} {%/if%}

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 Mohan_Dugganab

When one of absolute and toInt functions are applied, you would have only the integer or the absolute value.

 

following if part won't be satisfied and it would always return the else part.

{%#if age1=20.0 or age1=30.0 or age1=40.0 or age1=50.0 %} 

 

Also, there is a native age function https://experienceleague.adobe.com/en/docs/journey-optimizer/using/content-management/personalization/functions/dates#age which can be used in your case there by simplifying your checks even further

2 replies

vraghav
Adobe Employee
Adobe Employee
January 21, 2025

@pandiyarajanra1 are you getting any error? can you please share more details around "Not working"?

Level 2
January 21, 2025

Not throwing any error, but it is not showing any result as well as it is blocking all other offers in the system where adobe support team mentioned toInt function is causing issue. But, it is the function available for us to use. Do you see any other error in this code

somen-sarkar
Community Advisor
Community Advisor
January 21, 2025

Hi @pandiyarajanra1 ,

Few observations :-

In the dateDiff function, the first parameter is in milliseconds. Why is the first parameter in milliseconds while the second is in DateTime format? Will this provide the difference in days?

When comparing date differences, you should consider using the now() function to make the logic more robust for the next line of code. 

Additionally, when comparing age, ensure you use the correct comparison operator. The statement age1=20.0 assigns a value instead of comparing. Please check the use of the == operator for comparison.

Lastly, cross-verify the syntax of your conditional statements.

 

https://experienceleague.adobe.com/en/docs/journey-optimizer/using/orchestrate-journeys/building-advanced-conditions-journeys/main-functions-journey/date/functionnow

https://experienceleague.adobe.com/en/docs/journey-optimizer/using/orchestrate-journeys/building-advanced-conditions-journeys/syntax/operators#-12

https://experienceleague.adobe.com/en/docs/journey-optimizer/using/orchestrate-journeys/building-advanced-conditions-journeys/syntax/conditional-instruction

https://experienceleague.adobe.com/en/docs/journey-optimizer/using/content-management/personalization/functions/helpers

 

Thanks,

Somen

 

Mohan_Dugganab
Adobe Employee
Mohan_DugganabAdobe EmployeeAccepted solution
Adobe Employee
January 21, 2025

When one of absolute and toInt functions are applied, you would have only the integer or the absolute value.

 

following if part won't be satisfied and it would always return the else part.

{%#if age1=20.0 or age1=30.0 or age1=40.0 or age1=50.0 %} 

 

Also, there is a native age function https://experienceleague.adobe.com/en/docs/journey-optimizer/using/content-management/personalization/functions/dates#age which can be used in your case there by simplifying your checks even further

Level 2
January 22, 2025

yes, it is working now. but one thing is toInt is not working as expected. it was blocking whole offers. do you have any idea why?