Assigning Data to Fields
Return field values from your handler to populate or update fields in the running form. The SDK merges your response formData onto the current form state.
How it works
Your handler sets field values using record.SetField() and the SDK renders them in the corresponding widgets. The key must exactly match the Name property of the widget as set in the Form Builder.
Setting field values
// Inside your handler (e.g. Form_onClick or {widgetName}_onChange)
public async Task Form_onClick(string widgetName)
{
if (widgetName == "loadcustomerbtn")
{
var customer = await _db.Customers.FindAsync(record.GetRecordGuid());
record.SetField("firstName", customer.FirstName);
record.SetField("lastName", customer.LastName);
record.SetField("email", customer.Email);
record.SetField("phone", customer.Phone);
record.SetField("status", customer.StatusId.ToString());
record.SetField("createdDate", customer.CreatedAt.ToString("yyyy-MM-dd"));
}
}
Loading a record on form open
The most common place to assign data is in the LoadForm / FormInit handler — called when the form first renders:
public override async Task Form_onInit(bool isInitialLoad)
{
await base.Form_onInit(isInitialLoad);
if (!record.IsNewByRequest())
{
var employee = await _db.Employees.FindAsync(Guid.Parse(record.GetRecordGuid()!));
if (employee != null)
{
record.SetField("firstName", employee.FirstName);
record.SetField("lastName", employee.LastName);
record.SetField("department", employee.DepartmentId.ToString());
record.SetField("hireDate", employee.HireDate.ToString("yyyy-MM-dd"));
record.SetField("salary", employee.Salary.ToString());
}
}
}
Supported value types
| Widget type | Expected value |
|---|---|
| Input (text) | string |
| Input (number) | string or int/decimal |
| Input (date) | ISO 8601 string with timezone |
| Input (datetime) | ISO 8601 string with timezone |
| Textarea | string |
| Select | string matching a key in fieldAllowedValues |
| Checkbox | "true" / "false" or bool |
| Radio | string matching one of the allowed values |
The safest approach is to convert all values to string before placing them in formData. This avoids serialization edge cases, especially for dates and decimals.
Always assign date and datetime values as ISO 8601 strings with timezone from your backend. In C# the "o" round-trip format specifier produces the correct output:
record.SetField("createdAt", DateTime.UtcNow.ToString("o"));
// → "2024-03-15T09:30:00.0000000Z"
Assigning data to a table widget
Table widgets are populated by returning rows from a {widgetName}_onTableLoadData handler method. Each row must be an object with at least three reserved fields plus your data columns:
| Field | Description |
|---|---|
_id | Unique identifier for the row — used by row actions (edit, delete, etc.) |
_sk | Sort key — usually the same as _id |
_code | Form code for the record type |
public async Task<IEnumerable<object>> employeetbl_onTableLoadData()
{
return await _db.Employees
.Select(e => new
{
_id = e.Id.ToString(),
_sk = e.Id.ToString(),
_code = "EMPLTBL",
firstName = e.FirstName,
lastName = e.LastName,
department = e.DepartmentId.ToString(),
status = e.Status
})
.ToListAsync();
}
Every row must include _id, _sk, and _code. Without them, row actions (edit, delete, open modal) will not work correctly.
Clearing a field
Set the field value to an empty string to clear it:
record.SetField("phone", "");