Skip to main content
Code action

Code, AI, Action

Georg Olafsson avatar
Written by Georg Olafsson
Updated over a month ago

When implementing a new workflow, it can be very easy to get stuck on a particular problem that basic actions can not solve. Many of these problems are very niche and are not obvious right away when planning the workflow in advance.

These can be very specific problems, for example:

  • You have an onboarding workflow for a new employee where the requirement is to add information from an Onboarding form to the HR system but the HR system only accepts English letters

  • I receive a "First day of work" date from a supervisor but I need the first working day before that date

  • I received a "Date of birth" from my HR system but I want to know when this persons next birthday is & if it is a big birthday that requires special celebrations

  • I have an integration action that returns a list of items but I only want to use specific items, based on a defined criteria

The list is really endless.

You don't have to know how to code to use the action!

The action comes with a code editor which allows anyone to add / edit code but with our built in AI code generation tool, you can generate new code or update existing with simple prompts.

Here is one example where we add a prompt that gives use the persons next birthday and if it is a big birthday or not, all based on the date of birth of said person (see example below for more details).

So how does it work?

Here is a quick example with an easy employee birthday journey!

We have a list of current employees - this can come directly from your HR / Payroll software through an integration or you can import them directly to journeys.

In the workflow, this is the criteria that we have:

  • If the employee has a normal birthday I want to notify the supervisor one day before

  • If the employee has a big birthday I want to notify this persons supervisor two days before and order some flowers

Of course this can have a lot more actions but we will keep it simple for the purpose of demonstration.

We have the journey "ready" but we cannot complete the setup as we are missing the two required pieces of information:

  • When is this persons next birthday

  • Is that birthday a big birthday or normal?

As you can see in the first image above, we only have the date of birth for these individuals so we need to use that in order to find out what we need.

This is where the Code action comes in!

Add the action to the workflow

Now configure the input that the code action will use - in this case it is the Date of Birth

Open the code editor to add or generate the code snippet by AI.

In our case we will use AI with the prompt: "You are given a date of birth for a person, please return the date of this persons next birthday and if that birthday is a big one. This should handle leap years as well."

After the code is generated we are going to test if this will actually work by adding a date of birth to the test functionality. In our test case we see that the action will return the Next birthday date as a "Date" variable and then "If big birthday" as a boolean (true / false).

We can now move on and finish the journey!

First we complete the conditions, check if it is a big birthday (if true, we move on)

And since we have the next birthday date, we can now configure the "Wait until # date" action to pause the journey until 2 days before the birthday.

Complete the same step for the "normal" birthday path and the Journey is now ready!

Code editor details

The code action follows basic Python principles so you can not import additional features like calling third-party systems.

Additionally the action handles the following

time: The time module
datetime: The datetime module
today: datetime.date.today()
parse_date: dateutil.parser.parse()
timedelta: datetime.timedelta
random: The random module
json: The json module
abs, min, max, sum as well

The "output" variables are defined in the "Returns" section of the code and in the return section

Declaration

Return

Update vs Replace

If you are happy with the code that was generated, you can always decide to update that instead of having the action generating new code.

Here you can select which functionality you want

Did this answer your question?