Using Imported Functions and Data

Note:

This topic is intended for administrators and developers who use imported functions and data in Field Service Management (FSM) Mobile expressions.

An imported JavaScript function can provide a reusable calculation. An imported JSON file can supply fixed data for a calculation. For file registration, import IDs, complete file examples, file updates, and offline caching, see FSM Mobile Scripting and Customization.

Browser imports do not make their functions or data available to server-side template tags. Independent page interactivity has different initialization and cleanup requirements. For more information, see FSM Mobile Scripting and Customization.

This topic includes the following sections:

Expression-Callable Functions

A function called by an FSM Mobile expression must return its result synchronously and produce consistent results from its supplied inputs. Pass the required element values as arguments. Keep the function free of DOM changes, form-state changes, record writes, network requests, timers, and other asynchronous work. FSM Mobile can call it again whenever a referenced input changes.

The following property fragment assumes that the imported function customLineTotal is available and that quantity and unitPrice are Number elements in the expression's scope:

            {
  "value": "customLineTotal(quantity.value, unitPrice.value)"
} 

          

The references to quantity.value and unitPrice.value establish the inputs. Use the function name declared by the JavaScript file. Its import ID does not rename the function or add a prefix to its name. For the complete function definition and registration example, see FSM Mobile Scripting and Customization.

Imported JSON Data

The JSON import ID names the global variable containing its parsed data. For example, if a JSON file registered as customRates_v1 provides a numeric standard rate, a Number element can use this property fragment:

            {
  "value": "hours.value === null ? null : hours.value * customRates_v1.standard"
} 

          

This example assumes an available Number element named hours. Its hours.value reference establishes the changing local input. The imported data supplies a fixed rate. Changing that data is not a local element change that triggers recalculation. For the complete JSON file, registration, naming, and update procedure, see FSM Mobile Scripting and Customization.

Additional Information

Related Topics

General Notices