LCS - Basic Actions

This document will go over actions and how they work. It will show you how to create action steps, specifically the condition action step and how to add a step using the raise error function brought into your application from the block store.

 Actions are a series of steps (action steps) that are carried out after a user either clicks on a button or submits a form. Actions can be simple and just save data to a model or quite complex with lots of logic and action steps. They are quite flexible. 

 Actions are different than interactions. Interactions only modify components on a page. Actions can work with Models, save and update data, and can contain complex logic. Professional software developers can think of actions as the business logic or possibly the controller logic in MVC.  

 Actions are only created via the Action button or the Update and Create forms. Actions are automatically generated for you for Create Form or Update Form components, and they already do the work of creating or updating data. However, you can edit them to add additional functionality and logic. The Action Button does not have any logic in its action initially. It generates an empty action, and you can set up any action steps.  

Working with Actions 

 There are two ways to work with Actions.  

  1. Select the component that the action is for, e.g., an Action Button. Click on the Edit Icon on the sidebar that appears on the left-hand side of the page to edit the action. 

  

 

The action for a create or update form can be accessed from the form component. Make sure you select the form in the page builder. Then select the edit icon to edit the action. We will be working with a create form action further below. 

Another way to view an action is to select the lightning bolt icon from the left-hand menu, known as the builder bar in Betty Blocks. That will let you view all the actions for your application. Select the action you want to edit. It is important that you have given your actions a good name to use this method, otherwise it can be difficult to find the right one, as in the image below. See Development Naming Conventions for Betty Blocks for more tips on naming in Betty Blocks.

 

When you edit the action, you will see a screen like the following. There is a lot going on there, but the main point is there is a “Start” box and a “Finish” box which are the two basic action steps. Actions are made up of steps like the start and finish boxes just mentioned. You can add additional steps and branching and loops between those. It works like a flowchart.  

Select the Setting button on the upper right of the screen to work with the overall settings for the action. 

Naming your action and setting up permissions 

These are important first steps. It is important to give your action a name, usually with your page name as a part of it. This makes it easier to find it later. One example is [PB] Project Details – Create Action. See Development Naming Conventions for Betty Blocks for more tips on naming in Betty Blocks.  

 

The second step is to update the permissions. Otherwise, the actions will not be available to your users.  

Go to the permissions tab. Make sure the appropriate permissions are allowed. If your action is for anyone in the public who is not logged in, then you must turn off the Private Action. You can then jump to the next section for the start box. To authorize roles, continue setting up permissions for your users. 

For SSO (Single sign on) applications, you will need to specify Web User for the authentication profile and select which roles can access the action. 

 

Typically, you will want to give Web Users access to the action for SSO secured pages. If you are using a back office, you will probably want to limit this role to admins or managers. Change the red X to a green checkmark to allow users with that role to perform this action. 

The Start Box 

The second place to go to for an action is the Start Box. If you have any dialog boxes open then close them. Select the orange Start button to see the input variables (passed from the page) and access Action variables (added by you). If you select that you will see a dialog box that will contain any input variables that passed along to your action. 

 

Input Variables 

This is the first tab that you see when viewing the start box. If you set up a create or update component, these will already be filled in for you like the following image shows. If the action is a result of an Action button, the input variable will be the one you named in the Action button in page builder under “PASS VALUE TO ACTION.” Action buttons can only pass one input variable to an action. Input variables are available to use in any action step in your action. 

 

Action Variables 

The next tab over is for action variables. An action variable is a variable that you create specifically for the action. Once you create these variables you can use them through the action in other action steps. One example is looking up data from another model you want to use later in the Action. Any model can be retrieved. Another example is a variable that holds a price of something. You might need that variable throughout your action so you can set it up here. 

  1. Select Add. 

 

  1. Select the variable type. If it is a text or a number, all you need is the variable name. If it is a record, you will most likely apply a filter to it. In this example, we will add a record that looks up a project based on the name. Select Record for the Variable Kind. Give it a name like Record Exists. Select the Model Button and then select Project from the dropdown list. 

 

There are other options for variable kinds in the image above.  

    1. Text. This is useful for text such as an email that you might want in multiple places in your action.  

    2. Number. This is useful for such things as a constant price that is used throughout the action. 

    3. Collection. This looks up a collection which is a bunch of records. Then you can loop through them and do something with each record in an action step. 

    4. Checkbox. This is useful for setting something to checked or unchecked. That can be useful for branching with a condition action step. 

  1. After you have selected the model, elect the Create filter rule button to bring up the filter dialog box. Select the property you want to match. In this case we are going to select the Name property. The filter rule limits the records to only ones matching the filter. In this case we will only want records that match the Name from our input variables.  

 

  1. Next, select the variable or type in a search term that you want to match. In this case, we will select the variable called Name. The variable Name comes along automatically from the create form.  

 

Make sure you hit the Apply button afterwards before hitting save. It is easy to forget this. 

 

Now that you have this record looked up you can use it later in the action. 

Action Steps 

Action steps are the parts of your application. The initial ones are Start and Finish. There are many action steps you can use and download as blocks from the block store. We are going to continue with the Conditional Action step, but here are some examples of useful action steps: 

Use the Create Record action step to create a record. See the Create Record Article for more information. 

Use the Update Record action step to update a record. See the Update Record Article for more information. 

Use the Expression Action Step to use expressions and the loop action step to use loops. See the Expression and Loop Article for more information. 

Condition Action Step. 

Use the condition action step to put some logic in the action. You can put in conditionals to create branches in your actions just like a flow diagram. This is quite common to do different action steps depending on the user’s input. For example, before creating a record we can first check to see if the record already exists and only create it if it does not exist. The condition action step looks like the following. 

 

Tip for professional software developers: This is just an If…Then or If…Then…Else statement.  

Drag the “Condition” action step from the left-hand side and drag it to the point you will want to check. In this case it is right above the Create Record action step. You will see it create the branches. Path 1 is the branch that the condition will take if the condition is TRUE. You can even name it TRUE if that helps. 

  

Select the Condition action to open the dialog box to work with it. We are going to set things up to try to see if a record already exists for the project, so we do not enter in a duplicate project. We are going to use the Record Exist action variable that we created earlier. Under “First, check if” box, put in a readable name for the check. By default, it says, “Path 1” so replace that. In this example we are going to put in “Record already exists” for the first path.  

Next, we apply a filter which is the logic step that determines if we are taking this path or the other path. This filter is like other filters found in Betty Blocks. If whatever filter we set here is true, then this path (Record already) exists will be taken.  

 

Select the “(x)” to bring up a list of available input variables that are currently defined at this point in the action diagram. Remember that you can create input variable in your “start” action step and in expressions at any point along the pathway.  

In this case we will select the input variable we created earlier called, “Existing Record” and select the “Select” button.  

 

The next dropdown will change to “Exists” or “Does not exist.” In this case we will select “Exists” because we are going to go down this path if the record already exists. If the record does not exist, then the action will continue down the “Else” path.  

 

You can add additional pathways here with the “Add path” button so there are more than two branches. For example, if a record already exists then you could add an additional check here to see if some variable in the existing record matches one of the input variables and then decide how to continue. In this case we do not need any additional checks, so we are done with this action step. You can change the name of the other branch from “else” to something like “else the record does not exist” if you like, but it is fine to just leave it as “else.” 

Select the “Save” button and the action step is saved.  

 

The last step is to drag the Create Record action to the Else block. That will be triggered anytime the record does not already exist. After dragging the Create Record action step your action should look like the following image. 

 

For the “Record Already Exists” branch we need to alert the user to this fact. One effective way is the “Raise Error” action step which we can get from the block store. 

Adding blocks from the block store  

There are lots of additional action blocks that you can download from the action store as well. Once we install a block, we can drag it into our action like any other action step. You can view them by selecting the block store icon on the lower left of the screen. We will walk through adding the Raise error block to your application with the next section. 

Raise error block 

The raise error block is useful to alert the user of a problem. Download the block to your application by selecting the Block Store button in the lower left of your screen.  

Search for “raise error” in the search box.  

Select the View details button to bring up the screen to add it to your application.  

Select the Install Block button to add the raise error action to your application. A dialog will appear. Select the organization your application is in and then select the application itself from the dropdown lists. Select Install block to complete the installation.  

Once added, it will be available to use in any action in your entire application. Go to any action and you will see it in the list of available action.  

The raise error block can be dragged to your action diagram anywhere you like. In this case we are going to drag it under the “Record Already Exists” action step to let the user know that the record already exists and prevent duplicate records.  

After dragging the raise error action step to the appropriate location just select it to bring up the dialog box on the right side of the page. Type in the error message that you want the users to receive and select the “save” button and you are done. 

Sub Actions 

Sub action is a block you can download from the block store. A sub action allows you to call an existing action within the current action. For example, if you have an action that sends email that is set up with your SMTP settings, you can call that action from any other action in your application with a sub action. You just need to provide it with the recipient, subject, return address, and body to send the email. You do not need to duplicate the SMTP information.  

Another example is if you want to do a create record action in your current action, but you already have a create record action in a different page. You can call that existing create record action in a sub action here. In these examples you are reusing existing actions rather than duplicating them in multiple actions.  

To use sub actions, you need to install the sub action block from the block store. Install it using the same steps as the Raise Error Block section above. Once installed, it will appear in the action steps list on the left side of the page. 

Drag the Sub Action step into your action. Continuing along with our current examples, the action should look like the following image. 

Select the Sub Action step to bring up the dialog box. Select the existing action that you would like to perform here. All the available actions in your application are shown in a dropdown list. In this case we are going to use an existing action that sends an email. 

For this action, you can add the input variables that this sub action needs. Just select the Add button repeatedly until the available input variables are shown. For more information on email set up see Email set-up within an application.  

Fill in the appropriate data for the email. Use the (X) button to fill in the needed data for each of those options using your existing variables in your action. Otherwise type in the text that you want.  

 After selecting Give it an output name for the AS text box.  

Finally, select Save and your sub action will be configured successfully. 



KeywordsActions, Blocks, Action Steps, Start, Finish, action variables, input variables, condition, raise error, sub actions   Doc ID135088
OwnerMatt M.GroupLow Code Solutions
Created2024-01-29 13:25:08Updated2024-02-06 13:45:40
SitesDoIT Enterprise Business Systems - Low Code Solutions
Feedback  0   0