4D for Mobile Tutorial – Create actions

Actions allow users to interact with the application to change the customer’s address, add a new contact and modify a picture.

In the 4D language, an action allows you to add, edit, and delete an entity or a selection entity. But also, it can simply execute a method of your 4D server.

Why an action

You might wonder why you need to define an action to do simple operations such as add, edit or delete.

Remember that a mobile device can be offline and work without an Internet connection. When reconnecting to the network, the mobile device makes the data synchronization. But, in the meantime, the record may have been modified by another person, or, with a business example, an item may be out of stock, a payment already received, etc.
So an action allows your business logic to be consistent and to be checked. Before executing the action on the 4D server, you can check if it is valid and consider another solution – or reject the action and inform the mobile user.

Defining your first action

In this tutorial, we will see how to deal with a simple action to change the status and the percentage of completion.

We have prepared the ‘On Mobile App Action’ database method and the 4D methods like ‘modifyStatus’ called by the database method. In the video, add an action in the project to modify an entity or an entity selection, and we will show you how to link them to the base method.

Using action parameters

In this tutorial, we’re going to go further and create actions with the parameters:

  • an Add action to create a new task,
  • an Edit action that will allow you to edit existing tasks from the application,
  • a Delete action to delete an entity.

 

And we will follow step by step the modification of an entity.

Offline actions

An application user can modify a record everywhere, even when working offline. All these tasks are placed in the Pending actions list until the network is accessible. Once the user is online, all pending actions are consistently synchronized, executed, and then visible in the Completed actions list.

Rejected actions

You may reject an action sent to the server by mobile users for any given reason. For example, this may be because the action parameters sent do not match the expected values on the server side.

In that case, you can send feedback to your app users, telling them that something went wrong server-side using statusText and error properties. Then, the user updates the pending task and sends the action again.

Next…

Voilà! You now know how to add, modify or delete an entity or entity selection in your mobile application. You also know you can call a 4D method to send an email, for example.

To go further, you can continue with the blog or the documentation.

Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.