JS activity or Query Activity | Community
Skip to main content
Level 5
March 20, 2024
Solved

JS activity or Query Activity

  • March 20, 2024
  • 1 reply
  • 1287 views

Hi there,

 

I have a requirement where I need to determine whether the DateOnly(column1 + 11 days) is greater than the DateOnly(column2 + 21 days). If this condition is met, I'll return column1 and check if it matches today's current date. Otherwise, I'll return column2 and check if it matches today's current date.

 

I've set up a query activity to retrieve a group of audiences, and now I need to filter out the audience further based on the above conditions and qualified users need to be processed further in the workflow. I'm wondering if this filtering can be done directly through the query activity itself, or if I need to use a JavaScript (JS) activity instead.

If it needs to be done through a JS activity, I would appreciate it if you could provide some sample code references.

 

I understand that this can be achieved using a CASE statement, as shown below, but I'm uncertain if it's possible through the JS activity:

 

SELECT
CASE
WHEN DATE_ADD(column1, INTERVAL 11 DAY) > DATE_ADD(column2, INTERVAL 21 DAY) THEN DATE_ADD(column1, INTERVAL 11 DAY)
WHEN DATE_ADD(column2, INTERVAL 21 DAY) > DATE_ADD(column1, INTERVAL 11 DAY) THEN DATE_ADD(column2, INTERVAL 21 DAY)
END AS final_result
FROM
your_table_name
WHERE
CASE
WHEN DATE_ADD(column1, INTERVAL 11 DAY) > DATE_ADD(column2, INTERVAL 21 DAY) THEN DATE_ADD(column1, INTERVAL 11 DAY)
WHEN DATE_ADD(column2, INTERVAL 21 DAY) > DATE_ADD(column1, INTERVAL 11 DAY) THEN DATE_ADD(column2, INTERVAL 21 DAY)
END = CURRENT_DATE;

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 Amine_Abedour

Hello @rvnth,

 

it's feasible via a query activity, bellow an exemple.

 

Content of the expression is :

Iif(AddDays(DateOnly(@created) , 11) > AddDays(DateOnly(@lastModified) , 21) , AddDays(DateOnly(@created) , 11) , AddDays(DateOnly(@lastModified) , 21))

I took @creates as your column1 and @lastModified as your column2.

The sql query generated by this is :

SELECT R0.iRecipientId FROM NmsRecipient R0 WHERE ( CASE WHEN AddDays(DateOnly(R0.tsCreated, 'Europe/Paris'), 11) > AddDays(DateOnly(R0.tsLastModified, 'Europe/Paris'), 21) THEN AddDays(DateOnly(R0.tsCreated, 'Europe/Paris'), 11) ELSE AddDays(DateOnly(R0.tsLastModified, 'Europe/Paris'), 21) END = DateOnly(GetDate(), 'Europe/Paris') )

Br,

 

1 reply

Amine_Abedour
Community Advisor
Amine_AbedourCommunity AdvisorAccepted solution
Community Advisor
March 21, 2024

Hello @rvnth,

 

it's feasible via a query activity, bellow an exemple.

 

Content of the expression is :

Iif(AddDays(DateOnly(@created) , 11) > AddDays(DateOnly(@lastModified) , 21) , AddDays(DateOnly(@created) , 11) , AddDays(DateOnly(@lastModified) , 21))

I took @creates as your column1 and @lastModified as your column2.

The sql query generated by this is :

SELECT R0.iRecipientId FROM NmsRecipient R0 WHERE ( CASE WHEN AddDays(DateOnly(R0.tsCreated, 'Europe/Paris'), 11) > AddDays(DateOnly(R0.tsLastModified, 'Europe/Paris'), 21) THEN AddDays(DateOnly(R0.tsCreated, 'Europe/Paris'), 11) ELSE AddDays(DateOnly(R0.tsLastModified, 'Europe/Paris'), 21) END = DateOnly(GetDate(), 'Europe/Paris') )

Br,

 

Amine ABEDOUR
rvnthAuthor
Level 5
March 21, 2024

Hi @amine_abedour ,

 

Thank you so much for your help. This is actually giving me the column2+21 days = getDate(currentDate) values. Here is the attached screenshot:

 

 

I want to get the end result whichever(column1 or column2) date is bigger that should check if it is equal to currentDate then provide those in result.

 

please suggest

rvnthAuthor
Level 5
March 21, 2024

I am trying to construct something as below
MAX(AddDays(DateOnly(@column2) , 21),AddDays(DateOnly(@column1) , 11)) equal to currentDate

 

but it is giving me an error. Please suggest