<?xml version="1.0" encoding="utf-8"?><finScript version="1.00" exportedUtcDate="2018-08-12T23:11:59.0000000"><CreatedUserId>ADMIN</CreatedUserId><CreatedUtcDate>2018-06-19T21:22:15.7030000</CreatedUtcDate><UpdatedUserId>ADMIN</UpdatedUserId><UpdatedUtcDate>2018-06-19T23:22:49.3600000</UpdatedUtcDate><ScriptId>WSCLIIMP</ScriptId><Description>Web Service - Client Import</Description><ScriptType>WebServiceWebApi</ScriptType><Active>true</Active><AllowUI>false</AllowUI><Category /><Code>Option Explicit On
Option Strict On

' ######################################
' Web Service to import client accounts.
'
' Current Version: 1.00.00 (19/05/2015)
'
' Usage: Web Service API
'
' Revision Notes
' ==============
' 19/05/2015  1.00.00   ISS.ME    Created.
' ########################################

#include "FL.WSCLASS"

Public Function Main(request As finwsHttpRequest) As finwsHttpResponse

  ' Parameters:
  '   request - The HTTP request details

  Dim Client As finClient
  Dim ClientId As String
  Dim CustomClient As clsCustomClient
  Dim CustomClients As clsCustomClients
  Dim ErrorCode As String
  Dim ErrorStatusCode As HttpStatusCode
  Dim obj As Object
  Dim Ok As Boolean
  Dim RecordCount As Integer
  Dim ResponseDetail As clsResponseDetail
  Dim ResponseDetails As clsResponseDetails

  ' Assume Success
  Ok = True

  ' Initialise
  Client = finBL.CreateClient()
  CustomClients = New clsCustomClients()
  ResponseDetails = New clsResponseDetails()
  ErrorStatusCode = HttpStatusCode.BadRequest

  ' Validate User
  Select Case request.AuthenticatedUserType
    Case isefinwsAuthenticatedUserType.User
    Case isefinwsAuthenticatedUserType.WebAdmin
    Case Else
      Ok = False
      ErrorCode = "AuthenticatedUserType.Unauthorised"
      ErrorStatusCode = HttpStatusCode.Unauthorized
      finBL.Error.ErrorBeginFormat("This custom Web Service is not available to Authenticated User Type '{0}'.", request.AuthenticatedUserType.ToString())
  End Select

  If Ok Then
    If finBL.Runtime.WebUtilities.DeserialiseXmlStringToObject(request.RequestText, GetType(clsCustomClients), obj) Then
      CustomClients = DirectCast(obj, clsCustomClients)

      If CustomClients IsNot Nothing Then
        ' Loop through imported custom clients
        For Each CustomClient In CustomClients
          ' Reset
          ClientId = ""

          ' Initialise response object
          ResponseDetail = New clsResponseDetail()

          ' Check for an existing client
          If finBL.Database.GetRecordCount("Client", String.Format("[ClientId]={0}", finBL.Database.FormatSqlString(CustomClient.ClientId)), RecordCount) Then
            With Client
              ' Set ClientId if we returned one
              If RecordCount &gt; 0 Then
                ClientId = CustomClient.ClientId
              End If

              ' Load existing/new client
              If .Load(ClientId) Then
                ' Update client fields
                .ClientId = CustomClient.ClientId
                .FirstName = CustomClient.FirstName
                .LastName = CustomClient.LastName
                .DateOfBirth = CustomClient.DateOfBirth

                ' Save client
                If .Save() Then
                  ResponseDetail.Status = "Success"
                  ResponseDetail.Message = String.Format("Successfully saved client: {0}", .ClientId)
                Else
                  ResponseDetail.Status = "Failed"
                  ResponseDetail.Message = String.Format("Failed to save client: {0}", .ClientId)
                End If
              Else
                ResponseDetail.Status = "Failed"
                ResponseDetail.Message = String.Format("Failed to load client: {0}", ClientId)
              End If
            End With
          Else
            Ok = False
            Exit For
          End If

          ResponseDetails.Add(ResponseDetail)
        Next
      End If
    End If
  End If

  ' Return Response
  If Ok Then
    Return request.CreateResponse(HttpStatusCode.OK, ResponseDetails)
  Else
    Return request.CreateErrorResponse(ErrorStatusCode, String.Format("Failed to execute custom Web Service Script '{0}'.", ScriptInfo.ScriptId), ErrorCode, String.Format("{0}.{1}", finBL.Error.Message(), finBL.Error.Details))
  End If

End Function</Code><Language>VisualBasic</Language><Notes>Sample XML:

&lt;Clients xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;Client&gt;
    &lt;ClientId&gt;&lt;/ClientId&gt;
    &lt;FirstName&gt;Bob&lt;/FirstName&gt;
    &lt;LastName&gt;Testers&lt;/LastName&gt;
    &lt;DateOfBirth&gt;1980-08-12T00:00:00&lt;/DateOfBirth&gt;
  &lt;/Client&gt;
&lt;/Clients&gt;</Notes><PermissionKeyExecute /><RunWithoutPrompts>false</RunWithoutPrompts><TemplateText /><TemplateTextBookmarks /><TimeoutSeconds>60</TimeoutSeconds><WebServiceName /><WebServiceAllowAnonymous>false</WebServiceAllowAnonymous><WebServiceAllowClient>true</WebServiceAllowClient><WebServiceAllowUser>true</WebServiceAllowUser><WebServiceAllowWebAdmin>true</WebServiceAllowWebAdmin><WebServiceSendDebugInformation>false</WebServiceSendDebugInformation><ParametersType>Custom</ParametersType><Parameters><ISParameterDefs version="1.00"><Parameters><Parameter name="SampleJson" type="Text"><BlankTip /><Caption>Response</Caption><StandaloneOnly>false</StandaloneOnly><TooltipText>{"Accounts":null,"ClientId":"","DateOfBirth":"1980-02-10T00:00:00","ErrorMessage":null,"FirstName":"Martin","LastName":"Elsworth"}</TooltipText><DefaultValueExpression /><Enabled>true</Enabled><HideDescription>false</HideDescription><IndentLevel>0</IndentLevel><Mandatory>false</Mandatory><NonPersistable>false</NonPersistable><ReadOnly>false</ReadOnly><ReadOnly2>false</ReadOnly2><Value /><Visible>true</Visible><MaxLength>0</MaxLength><Rows>1</Rows></Parameter></Parameters></ISParameterDefs></Parameters></finScript>