Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 1522 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

filemaker-server-17-icon.pngWith MBS Xojo Plugins 20.4 we include a new MBS Xojo FMAPI Plugin part with a few new classes to connect to a Claris FileMaker Server:

The FMDataMBS class does a Data API connection while the FMAdminMBS class provides methods for the Admin API. Both have FMConnectionMBS as base class for the core functionality to connect.

Connect

Lets connect to a server via Data API using user name and password:

// connect

Dim connection As New FMDataMBS
connection.Password = "admin"
connection.Username = "admin"
connection.Server   = "localhost"
connection.Database = "test"

Dim r As FMResponseMBS = connection.Login

If r = Nil Then
MsgBox "Failed?"
Else

MsgBox r.ErrorMessage

return

End If

To learn what databases are available, please use ListDatabases method in FMAdminMBS class.

Create Record

Next you may want to create a new record. For this we provide a dictionary with keys and values. The plugin passes data to the server in JSON and you may need to provide values as text or numbers as variants. If you need to upload a file to a container field, please use a second call with UploadToContainerField method later.

We specify the layout to use. This layout defines what fields are available to set. The request may include more parameters like a script to run. But here a simple create record example:

// now create a record

connection.Layout = "Testing"

Dim request As New FMRequestMBS
Dim fieldData As New Dictionary

fieldData.Value("First Name") = "Joe"
fieldData.Value("Last Name") = "Smith"
fieldData.Value("Title") = "Mr."
fieldData.Value("Company") = "Test Ltd."
fieldData.Value("Website") = "http://www.mbs-plugins.com/"

request.fieldData = fieldData

r = connection.CreateRecord(request)
 

If r.ErrorCode = 0 Then

// okay

Else

MsgBox r.ErrorMessage

Return

End If

Query Records

To query records, please specify the layout to use as that one defines which fields. With request object you can specify the limit and offset for the query to get paged results. Otherwise the default setting is to return first 50 records.

For a lot of operations, a layout must be specified. The layout defines which fields are available to set or query. Optionally you can specify a script to run before the query to gather the records. e.g. by doing a find operation in the script. You can also run a script to sort and specify in your request which portals to return.

// and query records on that layout

request = New FMRequestMBS

r = connection.GetRecords(request)

 

If r.ErrorCode = 0 Then

// okay

Else

MsgBox r.ErrorMessage

Return

End If

 

Dim Result As Dictionary = r.Result

 

Dim dataInfo As Dictionary = Result.Lookup("dataInfo", Nil)

If dataInfo = Nil Then

Break

Return

End If

 

Dim returnedCount As Integer = dataInfo.Value("returnedCount")

Title = Str(returnedCount)+" records."

 

Dim Data() As Variant = result.Lookup("data", Nil)

Dim fields() As String

Dim List As Listbox // some listbox to fill

Dim recordID   As Integer

 

For Each record As Dictionary In data

 

recordID  = record.Value("recordId")

fieldData = record.Value("fieldData")

 

Dim c As Integer = fieldData.Count

 

If fields.Ubound < 0 Then

// first time

Dim keys() As Variant = fieldData.keys

 

For Each key As String In keys

fields.Append key

Next

 

// set listbox heading

List.ColumnCount = c

For i As Integer = 0 To c-1

List.Heading(i) = fields(i)

Next

End If

 

List.AddRow ""

For i As Integer = 0 To c-1

List.Cell(List.LastIndex, i) = fieldData.Value(fields(I))

Next

Next

More

Please check our example projects for Data API and Admin API queries. You may write your own server monitoring application using the Admin API.

See also FileMaker 19 Data API Guide and Claris FileMaker 19 Admin API Guide.

For all queries and data transferred, FileMaker Server counts data going out and applies a 2 GB per user and per month limit. As a server has minimum 5 users, you have 120 GB/year or more available.

Please do not hesitate to contact us with your questions.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.