Working with Jobs

To work with Jobs there are 2 endpoints of interest. 

  • /api/JobTypes
  • /api/Jobs/

You do need to be thoroughly familiar with the concepts in WorkMobile of both Jobs and Jobtypes, their inter-relationships and the Jobs life-cycle.

The job types endpoint lets you return information about the types of jobs you can raise. It specifies which fields need to be supplied during the creation process and those that are available to be filled in by the mobile user.

You can also retrieve the schema document by which the user defined data is validated by calling 

/api/JobTypes/{id}/schema 

where {id} is the required JobTypeId. The schema document is described in more  detail further down.

For customers who have used the old XML WMBAPI API, we have retained a number of the key concepts whilst making two important improvements

  • Creating and allocating a job can be done in a single step - you no longer have to make an additional allocate API call
  • The job creation process is much faster.

Submitting job data consists of 2 parts. The first is to supply the concrete attributes associated with a job. Those are

  • Job Priority
  • The Estimated Start Date
  • A Description of the job that you can see on the summary page
  • The type of job you are creating
  • Who you are allocating the job to, a single user or a group using the job broadcast function

The second part is to specify the data that matches your user defined form and job type set up in WorkMobile.

Given the flexibility we provide in designing forms and specifying which fields are to be filled in for the user in the field and which by the portal user, we have to use a more fluid type of validation. 

To do this we use a JSON Schema Document. A sample document is displayed below.

{
  "_id": "10238",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "additionalProperties": false,
  "additionalItems": false,
  "properties": {
    "jobData": {
      "additionalProperties": false,
      "additionalItems": false,
      "properties": {
        "New Number": {
          "type": "number",
          "required": [
            "New Number"
          ],
          "minimum": -1000000,
          "maximum": 1000000,
          "pattern": "-{0,1}[0-9]+"
        },
        "New Radio Button List": {
          "type": "string",
          "required": [
            "New Radio Button List"
          ],
          "enum": [
            "One",
            "Two",
            "Three"
          ]
        },
        "New Checkbox": {
          "type": "string"
        },
        "New Drop-down": {
          "type": "string",
          "required": [
            "New Drop-down"
          ],
          "enum": [
            "One",
            "Two",
            "Three"
          ]
        },
        "New Calendar": {
          "type": "string",
          "required": [
            "New Calendar"
          ],
          "format": "date"
        },
        "New Textbox": {
          "type": "string",
          "required": [
            "New Textbox"
          ],
          "minLength": 0,
          "maxLength": 50
        }
      }
    }
  }

Taken together it can look a little daunting but breaking it into sections actually helps greatly.

The following section describes that the field with a unique name of 'New Number', must be numeric and be between -1000000 and 1000000.

        "New Number": {
          "type": "number",
          "required": [
            "New Number"
          ],
          "minimum": -1000000,
          "maximum": 1000000,
          "pattern": "-{0,1}[0-9]+"
        },


It specifies that field (New Number) must be supplied (it is required) and it must match the regular expression specified in the pattern property, an integer, optionally starting with a - symbol.

There are a number of good online resources to help you build up and validate your JSD - there is an excellent one here https://www.jsonschemavalidator.net/