Creating a Job

As a prerequisite you should be aware of the way the job functionality within WorkMobile works - especially Mobile and Operator editable fields. If you haven't seen this functionality we would encourage you to create some job types, jobs and go through the whole Job lifecycle paying attention to changing the Mobile user and Operator editable attributes on the Job Type editor screen.

Additionally, you should familiarise yourself with XSD documents and understand how the XSD changes as you change your job definition
 
If you haven't used XSD's before, a simple description is here
https://whatis.techtarget.com/definition/XSD-XML-Schema-Definition

To create a new job is straightforward, it is analogous to creating any other type of entity in the system. The standard attributes of the job are self explanatory are relate directly to the New Job screen in WorkMobile. The user defined data that 'fills' in the operator editable fields is by definition dynamic and the most complicated part of creating a job.

Data for the new job must be provided in XML. The required format is described in an XML Scheme Definition (XSD) document for each job type. You can retrieve this document, and validate your new job's XML before submission.

The url for the xsd can be retrieved from the jobType.XSDSchema document.

Once you have this document - depending on your form definition and requirements you can either

1. Use an online XSD to XML converter (https://www.liquid-technologies.com/online-xsd-to-xml-converter for example) to give yourself a template document. You can save this document in your project as a resource and then replace the sample values in your document by loading it into an XML DOM object and supplying your own values. Serialising this to a string and supplying it as the XMLData variable in the sample is the way to go if your structures are fairly static.

2. If you are trying to integrate dynamically to a wide range of forms, which can change without your knowledge or if you are perhaps integrating to a copy of the same form across a number Workmobile accounts. This may be if you are a partner and have a number of customers with a common set of solutions in each of their accounts then you may want to create something more dynamic where you 'discover'If you are using C# or can consume a DLL then there is a great piece of sample code to construct XML from an XSD dynamically that  is available under an apache license on GitHub @ https://github.com/mganss/XmlSchemaClassGenerator/blob/master/XmlSampleGenerator/XmlSampleGenerator.cs . 

At the bottom of this document is a sample XSD and the valid XML for a document defined in this way.

You will also notice from the code samples that the allocation of the job is a separate step. 

C#

// fetch job type specification
BOJobType jobType = new BOJobType();
jobType.JobTypeId = REQUIRED_JOB_TYPE;
jobType = service.RetrieveById(jobType, credentials);
string xsdUrl = jobType.XSDSchema;

// create job
BOJob job = new BOJob();
job.Description = "New Test Job - Repair 1104, M1 5BD";
job.EstimatedJobStartDate = DateTime.Now.ToString("dd-MMM-yyyy HH:mm");
job.JobTypeId = jobType.JobTypeId;
job.XmlData = JOB_XML;
int jobId = service.Add(job, credentials);

// allocate to a mobile user
BOJobAllocate alloc = new BOJobAllocate();
alloc.JobId = jobId;
alloc.MobileUserId = REQUIRED_MOBILE_USER_ID;
service.Add(alloc, credentials);

Java


// fetch job type specification
BOJobType jobType = new BOJobType();
jobType.setJobTypeId(REQUIRED_JOB_TYPE);
jobType = service.retrieveById(jobType, credentials);
String xsdUrl = jobType.getXSDSchema();

// create job
BOJob job = new BOJob();
job.setDescription("New Test Job - Repair 1104, M1 5BD");
job.setEstimatedJobStartDate(new SimpleDateFormat("dd-MMM-yyyy HH:mm").format(new Date()));
job.setJobTypeId(jobType.getJobTypeId());
job.setXmlData(JOB_XML);
int jobId = service.add(job, credentials);

// allocate to a mobile user
BOJobAllocate alloc = new BOJobAllocate();
alloc.setJobId(jobId);
alloc.setMobileUserId(REQUIRED_MOBILE_USER_ID);
service.add(alloc, credentials);

Sample XSD


<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="WMJobs" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="JobData">
<xs:complexType>
    <xs:sequence>
        <xs:element name="NewCheckbox" type="NewCheckboxType" />
        <xs:element name="NewDown" type="NewDownType" />
        <xs:element name="NewCalendar" type="NewCalendarType" />
        <xs:element name="NewNumber" type="NewNumberType" />
        <xs:element name="NewTextbox1" type="NewTextbox1Type" />
        <xs:element name="NewRadioButtonList" type="NewRadioButtonListType"
/>
        <xs:element name="NewTime" type="NewTimeType" />
    </xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="NewCheckboxType">
<xs:simpleContent>

<xs:extension base="NewCheckboxTypeBase">
<xs:attribute name="uid" type="xs:integer" use="required" fixed="1592" />
<xs:attribute name="required" type="xs:boolean" use="required" fixed="0" />
<xs:attribute name="editable" type="xs:boolean" use="required" fixed="1" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NewCheckboxTypeBase" id="NewCheckboxTypeBase">
<xs:restriction base="xs:boolean">
</xs:restriction>
</xs:simpleType>
<xs:complexType name="NewDownType">
<xs:simpleContent>
<xs:extension base="NewDownTypeBase">
<xs:attribute name="uid" type="xs:integer" use="required" fixed="1591" />
<xs:attribute name="required" type="xs:boolean" use="required" fixed="1" />
<xs:attribute name="editable" type="xs:boolean" use="required" fixed="1" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NewDownTypeBase" id="NewDownTypeBase">
<xs:restriction base="xs:string">
<xs:enumeration value="One" />
<xs:enumeration value="Two" />
<xs:enumeration value="Three" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="NewCalendarType">
<xs:simpleContent>
<xs:extension base="NewCalendarTypeBase">
<xs:attribute name="uid" type="xs:integer" use="required" fixed="1589" />
<xs:attribute name="required" type="xs:boolean" use="required" fixed="1" />
<xs:attribute name="editable" type="xs:boolean" use="required" fixed="1" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NewCalendarTypeBase" id="NewCalendarTypeBase">
<xs:restriction base="xs:date">
<xs:minInclusive value="1900-01-01" />
<xs:maxInclusive value="2100-12-31" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="NewNumberType">
<xs:simpleContent>
<xs:extension base="NewNumberTypeBase">
<xs:attribute name="uid" type="xs:integer" use="required" fixed="1588" />
<xs:attribute name="required" type="xs:boolean" use="required" fixed="1" />

<xs:attribute name="editable" type="xs:boolean" use="required" fixed="1" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NewNumberTypeBase" id="NewNumberTypeBase">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-1000000" />
<xs:maxInclusive value="1000000" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="NewTextbox1Type">
<xs:simpleContent>
<xs:extension base="NewTextbox1TypeBase">
<xs:attribute name="uid" type="xs:integer" use="required" fixed="1587" />
<xs:attribute name="required" type="xs:boolean" use="required" fixed="1" />
<xs:attribute name="editable" type="xs:boolean" use="required" fixed="1" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NewTextbox1TypeBase" id="NewTextbox1TypeBase">
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="NewRadioButtonListType">
<xs:simpleContent>
<xs:extension base="NewRadioButtonListTypeBase">
<xs:attribute name="uid" type="xs:integer" use="required" fixed="1594" />
<xs:attribute name="required" type="xs:boolean" use="required" fixed="1" />
<xs:attribute name="editable" type="xs:boolean" use="required" fixed="1" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NewRadioButtonListTypeBase" id="NewRadioButtonListTypeBase">
<xs:restriction base="xs:string">
<xs:enumeration value="One" />
<xs:enumeration value="Two" />
<xs:enumeration value="Three" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="NewTimeType">
<xs:simpleContent>
<xs:extension base="NewTimeTypeBase">
<xs:attribute name="uid" type="xs:integer" use="required" fixed="1596" />
<xs:attribute name="required" type="xs:boolean" use="required" fixed="0" />
<xs:attribute name="editable" type="xs:boolean" use="required" fixed="1" />

</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NewTimeTypeBase" id="NewTimeTypeBase">
<xs:restriction base="xs:time">
</xs:restriction>
</xs:simpleType>
</xs:schema>

 

XML Conforming to above XSD

<?xml version="1.0"?>
<JobData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://www.esayworkmobile.co.uk/xsd/156/198. xsd">
<NewCheckbox editable="1" required="0" uid="1592">1</NewCheckbox>
<NewDown editable="1" required="1" uid="1591">Two</NewDown>
<NewCalendar editable="1" required="1" uid="1589">2012-02-29</NewCalendar>
<NewNumber editable="1" required="1" uid="1588">12</NewNumber>
<NewTextbox1 editable="1" required="1" uid="1587">test</NewTextbox1>
<NewRadioButtonList editable="1" required="1" uid="1594">Two</NewRadioButtonList>
<NewTime editable="1" required="0" uid="1596">09:00:00</NewTime>
</JobData>