Workflows and scripts for the Field Service (Dynamics 365) mobile app

Administrators can use processes like Dynamics 365 workflows, Power Automate flows, JavaScript, and business rules and actions to help frontline workers and automate business processes. Some processes will work when the mobile app is running in offline first and others require internet connectivity. For more information, see this article: Mobile offline capabilities and limitations.

Dynamics 365 workflows and Power Automate flows

Workflows and flows are commonly used to run data validations and autopopulate data based on triggers and conditions. There are many things to consider when creating workflows and flows. Many Dynamics workflows are being replaced with Power Automate flows, so we recommend trying Power Automate flows first to be more future-proof. For more information, see this article: Comparison of workflows and flow.

Workflows and flows will only run with an internet connection. Workflows and flows will execute when the mobile app is running online or running in Offline First with internet connection. The mobile app can only run online when there is no offline profile configured. When the app is running in Offline First with an internet connection, the user can execute workflows and flows by first saving the record; when saved, the changers are synced to the server, which triggers the workflow or flow server-side. The user can then sync the offline data manually or wait for next sync cadence (5 minutes by default) to pull down the results of the workflow or flow.

Business rules

You can create business rules and recommendations to apply form logic without writing JavaScript code or creating plugins. Business rules provide a simple interface to implement and maintain fast-changing and commonly used rules. They can be applied to main and quick create forms.

Business rules will run online, offline first with internet connection, and offline first without internet connection.

Actions

With actions, you can perform operations, such as create, update, delete, assign, or perform action. Internally, an action creates a custom message. Developers refer to these actions as "messages". Each of these messages is based on actions taken on a record type. If the goal of a process is to create a record, then update it, and then assign it, there are three separate steps.

Actions will only run when the app is running online.

Offline JavaScript

JavaScript web resources can be added to mobile forms and downloaded with Offline First.

JavaScript will run Online, Offline First with internet connection, and Offline First without internet connection (basically all the time).

Note

Refer to this doc for any potential limitations by platform for WebResources in offline mode.

Offline JavaScript example

In some cases, an organization may want to run validation on certain field values after a technician updates an entity. For example, let's say you want to make sure the duration of a work order booking is at least two hours once a technician saves a record in the Field Service (Dynamics 365) mobile app.

Validation can be done with the help of some JavaScript and doing so works online and offline.

See the video onVideo symbol Field Service (Dynamics 365) mobile app: Offline JavaScript for more details.

Go to Settings > Customizations.

Go to the Bookable Resource Booking entity.

Go to Forms.

Go to the Booking and Work Order form.

Go to Form Properties in the top.

Screenshot of the lookup record dialog in Power Apps.

Create and add a new JavaScript web resource to the form.

Enter in the following code snippet:


        function TestOnSave(executionContext) {

            var formContext = executionContext.getFormContext(); // get formContext
            var duration = formContext.getAttribute("duration").getValue();

            formContext.ui.clearFormNotification("DurationErrorMessageId");

            if (duration < 120) {
                executionContext.getEventArgs().preventDefault(); // Stop the Save
                formContext.ui.setFormNotification("Duration must be greater than 2 hours", "ERROR", "DurationErrorMessageId");
        }
    }

In the event handlers section, change the event from onLoad to onSave of the form.

Handler properties within the form properties.)

Save and publish customizations.