Step 2: Define “After Update” Trigger
Last updated
Last updated
To define the "After Update" trigger, follow the steps below:
To create an After Update trigger, click the [+ After Update] button in the same entity.
The After Update Trigger is created. Label it as “joinDate_changed.” This trigger will update the DayMonthJoinDate field with a value of day and month based on the value in the Join_Date field.
To define variables for this trigger, go to the “Variables” tab of the Trigger. Two variables are already defined:
Variable Name: “Previous_Revision”, Data Type: (the entity where the trigger is created). This variable contains the value of the entity record before the update.
Variable Name: “Updated_Record”, Data Type: (the entity where the trigger is created) This variable contains the value of the entity record after the update.
To create a Variable, click the [+ Variable] button. Create four (4) more variables.
To store the values for list of strings, month, day, and day with month together, define the variables as follows.
To store the value of the current date as a list of strings define a variable as: Variable Name: “strList”, Data Type: select “string”, and check “List” This defines the data type as a list of strings. The format of the date and time in Langstack applications is “YYYY-MM-DD hh:mm:ss” or “YYYY-MM-DDThh:mm:ss” .
To store the value for the month in the current date, define a variable as: Variable Name: “strMonth”, Data Type: “string”
To store the value for the day in the current date, define a variable as: Variable Name: “strDay”, Data Type: “string”
To store the value for the day with month from the current date, define a variable as: Variable Name: “strDayMonth”, Data Type: “string” This variable will contain the value for the day and month in the current date.
To define the criteria for the trigger, go to the “Criteria” tab. To add a Criteria bar, click the (+) button.
To verify if the values of Join_Date in the previous and updated record are not the same, define the first Criteria bar as follows:
Select the Source as Variables>Previous_Revision>Join_Date. It is displayed as “Previous_Revision.Join_Date”.
Select Operator as “Is Not Equal”.
Select the Source as Variables>Updated_Record>Join_Date. It is displayed as “Updated_Record.Join_Date”.
To verify if the values of DayMonthJoinDate in the previous and updated record are not the same, define the second Criteria bar as follows:
Select the Source as Variables>Previous_Revision>DayMonthJoinDate. It is displayed as “Previous_Revision.DayMonthJoinDate”.
Select Operator as “Is Not Equal”.
Select the Source as Variables>Updated_Record>DayMonthJoinDate. It is displayed as “Updated_Record.DayMonthJoinDate”.
To define that if any of the Criteria bar is valid, Code tab>On True section should be executed, click on AND to select OR.
To define Actions if the criteria returns True, go to the Code tab>On True section. Add an Action by clicking the (+) button.
To split the day and time values into a list of strings, define the first Action as follows:
Select Action as “Split string”.
Select Target variable as “strList”.
Select Source string as Variables>Updated_Record>Join_Date>toString(). It will display as “Updated_Record.Join_Date.toString()”. This contains the value of the created record join date which is first converted to string.
Type Delimiter as “-” and press Enter. It will be added in a blue bubble. This variable defines that the string is split based on the encounter of the “-”. In this Action, the current date is split based on the delimiter and results in a list of strings i.e. [“YYYY”, “MM”, “DD hh:mm:ss”].
To get an item from the list of strings, add the second Action and define it as follows:
Select Action as “Get List item”.
Select Target variable as “strMonth”.
Select Source list as Variables>strList, which displays as “strList”. The current month's value is taken from the variable “strList”.
Type Index value as “1” and press Enter. This is the index position of the item to be taken from the string. In this case, the month is at 1. [“YYYY”, “MM”, “DD hh:mm:ss”] = [“(index value=0)”, “(index value=1)”, “(index value=2)”]
Select the “As Copy” checkbox. This defines that the Target Value will only contain a pointer to the index value and not hold the actual value of it.
To update the value of the day in a variable, add the third Action and define it as follows:
Select Action as “Update Variable”. This Action updates a variable from a source.
Select Target variable as “strDay”. At this point, after the split based on the delimiter “-”, the last part of the string contains the value of the day and time.
Select Value as Variables>strList>getLast(), which displays as “strList.getLast()”. This is the value of the last index position in the list of strings.
This Action updates the last part of the list of strings into the variable “strDay” i.e. [“YYYY”, “MM”, “DD hh:mm:ss”]
To separate the value of day from the time, add the fourth Action and define it as follows:
Select Action as “Split string”. This Action is for splitting the string into a list of items.
Select Target variable as “strList”. The value of the list of strings will be stored in this variable.
Select Source string as Variables>strDay, which displays as “strDay”. The value of string in this variable will be split into a list of strings.
Type Delimiter as “(space)” and press Enter. It will be added in a blue bubble. This variable defines that the string is split based on the encounter of the “(space)”. In this Action, the current date will be split based on the delimiter “ “ (space) and will result in a list of strings i.e. from the list [“YYYY”, “MM”, “DD hh:mm:ss”], the last item will be split into another list: [“DD”, “hh:mm:ss”]. This results in the value of day in the first index position and the time in the second index position.
To update the day's value from the list of string (day and time), add the fifth Action and define it as follows:
Select Action as “Update Variable”. This Action updates a variable from a source.
Select Target variable as “strDay”. The value of the Day in the list of strings will be stored in this variable.
Select Value as Variables>strList>getFirst(). It displays as strList.getFirst(). The first value in the list will be the source. [“DD”, “hh:mm:ss”]
To update the values of day and month in a variable, add the sixth Action and define it as follows:
Select Action as “Update Variable”. This Action updates a variable.
Select Target variable as “strDayMonth”. This variable contains the value of the day and month concatenated.
In the Value, first select Variables>strDay and press Enter followed by select Variables>strMonth and pressing Enter. Each variable will be displayed in a white bubble. This Action updates the values in the variables strDay and strMonth to the variable “strDayMonth”.
To store the concatenated values of day and month in the DayMonthJoinDate field of the new updated record, add the seventh Action and define it as follows:
Select Action as “Update Variable”. This action updates a variable.
Select Target variable as Variables>Updated_Record>DayMonthJoinDate. This is displayed as “Updated_Record.DayMonthJoinDate”. This variable contains the value of the day and month concatenated.
In the Value, select “strDayMonth". This Action updates the created record with the value of day and month joined together.
Finally, the sequence of actions will look as per the image below:
To save the entity, click the [Save] button.
To close the Entity, click the [Close] button.
Edit the value in the Join_Date or DayMonthJoinDate and click the [Save] button.
The displayed record will have the “DayMonthJoinDate” value updated as per the date in the Join_Date field. If there is no Join_Date value added, the system updates the value in the Join_Date to be “1970-01-01” and the same will be updated in the DayMonthJoinDate field.