Parsware
All articles

How-tos

How to build a phone app on the same data

Draw a phone app in the Application Studio that saves expense claims to the same table the desktop app reads, then use it on a phone-sized screen. How-to video H003, step by step.

A bright cover reading "How-to · H003: A phone app on your data", with "Saving to the table the desktop app uses" under it, the steps Phone frame → Form → List → Share, and two screens from the video.

How-to H003 · 4 min 50 s. A complete tutorial: every shape, every size and every line of code the video types, so you can draw the same app and use it on a phone. Every picture is a frame of the video.

Some claims are raised at a taxi rank, not at a desk. In this tutorial you draw a phone app on the claims table from H001. A claim saved on the phone is the same record the desktop app shows, because there is only one table.

The app has one screen:

  • a title, My claims;
  • two text boxes, for what the claim was for and its amount;
  • a Save claim button that creates the claim;
  • a list of the claims, newest first, drawn once and repeated for each claim.

Before you start

  • The Expense Claims solution from How to build a complete app, with the Expense Claim table (fab_expenseclaim), its Name (fab_name) and Amount (fab_amount) fields, and the Expense User role.
  • Robin Park with the Expense User role, to use the app.

How a Studio screen works

A Studio app is drawn, and then given behaviour with a few lines of BS Lang. Three ideas cover everything in this tutorial:

Idea What it means here
State What the screen remembers while somebody uses it. This screen holds claims (the list) and form (the claim being typed).
Binding A control reads its value from state, and a text box writes back to it.
Handler Code that runs when something happens: the screen opens, or a button is pressed.

Nothing refreshes by itself. The screen shows what its state holds, so every change ends by loading the list again.

Part 1: Draw the screen

1.1 Create the app

  1. Open Solutions, then Expense Claims, and select Studio apps in its rail.

  2. Select New and fill in the panel:

    Field Value
    Display name Claims on the go
    Description Raise an expense claim from your phone.
  3. Select Save, tick the app in the list and select Design.

The designer opens on an empty canvas: the Layers on the left, the properties on the right.

1.2 Add a phone frame

  1. Zoom out a little, so the whole frame will fit.
  2. Open the Frame menu and choose iPhone 16.
  3. In the properties, on the Screen tab, change — Graphic, no meaning — to — The screen —. This tells the platform the frame is the app's screen, not a drawing.
  4. On the Graphic tab, type the name Claims and press Enter.

1.3 Write the title

Select the Text tool, click near the top left of the phone, type My claims and press Escape.

1.4 Draw the two text boxes and the button

Drag each control from Controls onto the phone, then set its place and size on the Graphic tab (X, Y, width, height, in pixels from the frame's top left). Its words are set on the text inside it.

Control X Y Width Height Words
Text box 20 110 353 44 What was it for? (the hint inside the box)
Text box 20 166 353 44 Amount
Button 20 222 353 44 Save claim

The width is the phone's, less a 20-pixel margin on each side.

Select the Amount box and, on its Screen tab, choose A number. A phone then shows the number keypad for it.

These are the platform's own controls, so they look and behave like every other screen, in light mode and in dark.

1.5 Draw the list

  1. Select the Claims frame. From Elements, choose A list.
  2. On the Graphic tab, turn on Vertical auto layout, so the rows stack one under the other.
  3. Set its place and size: X 20, Y 290, width 353, height 540. That fills the rest of the phone.
  4. On the Screen tab, set it to scroll Down — words wrap.
  5. From Elements, choose A list item. It goes inside the list.
  6. On the list item's Screen tab, in One of these per, type state.claims. The app draws one item for each claim in the list.
  7. From Elements, choose A paragraph. It goes inside the list item. Set its X to 52 and its width to 290.

You draw one row, and the app draws one per claim.

The Application Studio drawing Claims on the go on a phone frame: a My claims heading, two text boxes, a Save claim button and a list item, with the Layers panel on the left.

Part 2: Give it behaviour

2.1 Add the screen's state

  1. Select the Claims frame and open its Screen tab.
  2. Select Add a state field and name it claims. Press Tab.
  3. Select Add a state field again and name it form. Press Tab.
  4. Open the code page. It has one row for each state field, binding and handler, and a full-size editor.

2.2 Starting values, and what happens when the screen opens

On the code page, set each state field's starting value.

claims starts as an empty list:

[]

form starts as an empty claim, one entry per field the boxes fill in:

{ fab_name: "", fab_amount: "" }

Screen opens runs once, when somebody opens the app. It loads the claims into claims, newest first:

loadRecords("fab_expenseclaim", "claims", { orderBy: "created_at_utc", descending: true });

loadRecords(table, stateField, options) reads the table's rows the signed-in person may see, and puts them in the state field you name. created_at_utc is the time each record was created, which every table has.

2.3 Bind the boxes and the row

Select each control, open the code page and set the row named below.

The first text box's Value, so what you type is written into the form:

state.form.fab_name

The Amount box's Value:

state.form.fab_amount

The paragraph's Text. Inside a list item, row is the claim that item is drawn for:

row.fab_name + " · " + format(row.fab_amount, "number")

2.4 The button

Select the Save claim button, open the code page and set its Pressed handler:

createRecord("fab_expenseclaim", { fab_name: getState("form").fab_name, fab_amount: num(getState("form").fab_amount) });
notify("Claim saved.");
setState("form", { fab_name: "", fab_amount: "" });
loadRecords("fab_expenseclaim", "claims", { orderBy: "created_at_utc", descending: true });

Line by line:

Line What it does
createRecord(…) Creates one claim from the form. A text box holds text, so num(…) turns the amount into a number first.
notify(…) Shows a short message, so the person knows it worked.
setState("form", …) Empties both boxes for the next claim.
loadRecords(…) Loads the list again, so the new claim appears in it.

2.5 Save and share

  1. Select Save in the designer.
  2. Close the designer. In the Studio apps list, tick Claims on the go and select Share.
  3. Tick Expense User and select Save.

Part 3: Use it on a phone

  1. On a phone, or in a browser window narrowed to phone width, sign in to the environment as Robin Park. The app list shows both apps: Expenses and Claims on the go.
  2. Open Claims on the go. It fills the screen, and the list is empty: Robin has no claims yet.
  3. Type Taxi to the airport and the amount 64.50.
  4. Select Save claim. The app says Claim saved., the boxes empty, and the claim is in the list as Taxi to the airport · 64.50.

The finished app on a phone: My claims, the two boxes, Save claim, and a saved claim reading Taxi to the airport · 64.50.

  1. At a desk, open the Expenses app from H001. The taxi claim is there, created by Robin Park a moment ago.

The Expenses desktop app listing the same claim, Taxi to the airport, created by Robin Park, amount 64.5.

If H001's approval process is published, saving on the phone started it too: the claim is already Submitted and waiting for Sam. The process belongs to the table, not to the app.

If something goes wrong

  • The list is empty after saving. The Pressed handler doesn't end with loadRecords(…), or the list item's One of these per isn't state.claims.
  • The rows draw on top of each other. The list's Vertical auto layout is off. The designer warns about this when you save.
  • The amount is missing in the desktop app. Check the Amount box's Value is state.form.fab_amount, and that the Pressed handler reads getState("form").fab_amount. A field's Required tick is checked on forms, so a script has to fill it in itself.
  • Robin doesn't see the app. It isn't shared with Expense User (step 2.5).

What you built

Two apps on one table. Nothing is copied or synchronised: the phone writes the record and the desktop app reads it, with the same rules, the same process and the same security on both.

Read more

Is there a task you would like to see done step by step? Tell us. parsware.com/contact