Add a work order - HxGN EAM - Version 11.07.01 - Customization & Programming - Hexagon

HxGN EAM Web Services Toolkit Programmer Help

Language
English
Product
HxGN EAM
Search by Category
Customization & Programming
HxGN EAM Version
11.7.1

The Submit button's click event handler calls the CallAddWorkOrderService routine, which will set up and call the AddWorkOrderService web service. The routine behaves the same as the previous AddAndGetWorkOrder sample with the following differences:

  • Like in the AddAndGetWorkOrder sample, we call the CopyValuesFromControls method of the ObjFieldLinkProvider to copy the values from the controls to the serviceData.WorkOrder object.

  • Next, we need to set the values that do not have a corresponding control. These are the organizations that were stored in the LookupButtonClickHandler.

    ' Set the values that do not map to a control

    Datastream.Reflection.FieldAccess.SetValue(serviceData.WorkOrder,_ "EQUIPMENTID.ORGANIZATIONID.ORGANIZATIONCODE",m_EquipmentOrg)

    If (ClassInputBox.TextLength > 0) Then Datastream.Reflection.FieldAccess.SetValue(serviceData.WorkOrder, "CLASSID.ORGANIZATIONID.ORGANIZATIONCODE",m_ClassOrg) End If

    If (LocationInputBox.TextLength > 0) Then Datastream.Reflection.FieldAccess.SetValue(serviceData.WorkOrder,_ "LOCATIONID.ORGANIZATIONID.ORGANIZATIONCODE",m_LocationOrg) End If

    If (CostCodeInputBox.TextLength > 0) Then Datastream.Reflection.FieldAccess.SetValue(serviceData.WorkOrder,_ "COSTCODEID.ORGANIZATIONID.ORGANIZATIONCODE",m_CostCodeOrg) End If

  • We are using the Datastream.Reflection.FieldAccess.SetValue function which automatically instantiates objects before assigning the value. This allows us to replace the following code:

    If serviceData.WorkOrder.EQUIPMENTID Is Nothing Then serviceData.WorkOrder.EQUIPMENTID = New WebServices.MP0023.EQUIPMENTID_Type

    End If

    If serviceData.WorkOrder.EQUIPMENTID.ORGANIZATIONID Is Nothing Then serviceData.WorkOrder.EQUIPMENTID.ORGANIZATIONID = _New WebServices.MP0023.ORGANIZATIONID_Type

    End If

    serviceData.WorkOrder.EQUIPMENTID.ORGANIZATIONID.ORGANIZATIONCODE=m_EquipmentOrg

with this:

Datastream.Reflection.FieldAccess.SetValue(serviceData.WorkOrder,_ "EQUIPMENTID.ORGANIZATIONID.ORGANIZATIONCODE",m_EquipmentOrg)

  • We also need to set the date/time values, which require special processing. The data entered in the control is first validated to make sure it is a date/time.

    ' Set the date fields

Dim dt As System.DateTime

If (DateReportedInputBox.TextLength > 0) Then Try

dt = DateTime.Parse(DateReportedInputBox.Text) Catch ex As Exception MessageBox.Show("Date Reported does not contain a valid date/time.", _"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

DateReportedInputBox.Focus () Exit Sub

End Try

serviceData.WorkOrder.REPORTED = CreateWSDateTime(dt, True) End If

  • The Reported property of the serviceData.WorkOrder is set to the result of passing the validated date/time to CreateWSDateTime. This function splits out the values that make up a date/time, such as Month, Day, and Year, and assigns them to the appropriate properties used by the web service to define a data/time.

  • The result of the call to the web service is passed to the CompleteServiceRequest method of the Session object. This method extracts the session ID returned by the web service call and stores it in the SessionId property of the Session object for later use.