Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Filtering a query based on an instance variable

Avatar

Avatar
Validate 1
Level 3
matt-gardner
Level 3

Likes

46 likes

Total Posts

13 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 3
matt-gardner
Level 3

Likes

46 likes

Total Posts

13 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
matt-gardner
Level 3

24-07-2017

In my workflow I am populating an instance variable with the last run date:

instance.vars.last_run_date = new Date()

Each time this workflow runs it populates the variable. 

My question is - how do I use this variable in a query node target selection - I want to only pull back records where the expression modification date > instance.vars.last_run_date is true.

I cannot find examples of how to do this. Any pointers would be super helpful.

Cheers,

Matt

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 3
matt-gardner
Level 3

Likes

46 likes

Total Posts

13 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 3
matt-gardner
Level 3

Likes

46 likes

Total Posts

13 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
matt-gardner
Level 3

26-07-2017

Thanks for input.  We did try the incremental query but in Adobe Campaign 7 it is not possible to get new and modified records via an incremental query.

In the end I created a workflow with a javascript node that read a last_run_date from a file and captured the current date-time - both values were written to instance vars to be used in later steps in the workflow:

// Get last_run_date from file

var f = new File("/path/last_run_date.txt");

f.open("r");

var line = f.readln();

f.close();

instance.vars.last_run_date = line;

// Store time process started

instance.vars.current_run_date = formatDate(new Date(), "%4Y-%2M-%2D %2H:%2N:%2S");

logInfo("Read last_run_date from file = " + instance.vars.last_run_date)

In the query node I could add a targetting rule to filter the table for records with a modification date on or after $(instance/vars/@last_run_date).

Finally after the query had executed I wrote the last_run_date back to disk in another javascript node:

var f = new File("/path/last_run_date.txt");

f.open("w");

f.write(instance.vars.current_run_date);

f.close();

logInfo("Saved current run date = " + instance.vars.current_run_date);

Seems a bit clunky but works!  I imagine there is a better way to avoid the use of an external file to store the last run date between runs of the workflow.

Answers (3)

Answers (3)

Avatar

Avatar
Boost 5
Level 2
_nkur
Level 2

Likes

11 likes

Total Posts

23 posts

Correct Reply

6 solutions
Top badges earned
Boost 5
Boost 3
Boost 10
Boost 1
Affirm 5
View profile

Avatar
Boost 5
Level 2
_nkur
Level 2

Likes

11 likes

Total Posts

23 posts

Correct Reply

6 solutions
Top badges earned
Boost 5
Boost 3
Boost 10
Boost 1
Affirm 5
View profile
_nkur
Level 2

28-07-2017

Hi Matt,

Have you consider options for this? I think it would a much cleaner way.

Regards,

Ankur A.

Avatar

Avatar
Validate 1
MVP
david_garcia1
MVP

Likes

106 likes

Total Posts

182 posts

Correct Reply

41 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
MVP
david_garcia1
MVP

Likes

106 likes

Total Posts

182 posts

Correct Reply

41 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
david_garcia1
MVP

26-07-2017

In a webApp, I usually do it like the following (https://db.tt/HDj12iCF1B )

Never tried it in a workflow:

$([/instance/vars/last_run_date])

Also try formatting the date i.e.

instance.vars.last_run_date = formatDate(new Date(), '%2D/%2M/%4Y %2H:%2N:%2S');

logInfo(instance.vars.last_run_date);

Avatar

Avatar
Give Back 50
Level 10
florentlb
Level 10

Likes

236 likes

Total Posts

1,109 posts

Correct Reply

239 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 200
View profile

Avatar
Give Back 50
Level 10
florentlb
Level 10

Likes

236 likes

Total Posts

1,109 posts

Correct Reply

239 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 200
View profile
florentlb
Level 10

26-07-2017

Hi Matt,

I'm not sure this can easily be done that way. Have you considered using the Incremental query? Targeting activities

This type of query can be used to find only new entries since its last execution. Which seems to me to match what you are trying to achieve.

Let me know if you have more specific requirements.

Florent.