Skip to content

Issue 420 Lookup Answers Unusable After Submit

Ed Mozley edited this page Nov 22, 2026 · 1 revision

πŸ”Ž #420 A lookup answer reached "what happens next" as "2, User Test"

GitHub #420, reported by @pappas81 Β· Forms, Workflows Β· fixed in 5.9.0 (#3109, #3110)

What you saw

A form asks Who is this for? with a Lookup field over People. Someone picks Ciara Doherty and sends it. The form's What happens next raises a ticket - and there is no way to make Ciara the requester.

Put {{submission.fields.Person}} in the ticket's subject and the ticket says:

ZZ #420 demo - the Person answer arrived as: 276, Ciara Doherty

That is the record number and the name glued together with a comma. It is not an email address, so it cannot be the requester email, and nothing else reaches the person's record. The only way round it was to hand the submission to an outside tool (n8n, say), look the person up through the API and raise the ticket from there - for data FreeITSM already had.

When the form was filled in by an analyst (not a signed-in portal user) and Requester email was left blank, it was worse: the ticket was simply not raised, with This request has no requester to raise a ticket for in the workflow log and nothing on screen.

What was wrong

A lookup answer is stored, on purpose, as both the record and the words it was given with:

{"id": 276, "label": "Ciara Doherty"}

The id is what makes it a lookup rather than a text box; the label is what the answer meant if the record is later renamed or deleted (see Forms lookup fields developer guide).

But the code that hands a form's answers to what happens next and to workflows had never been taught about lookups. It had one rule for anything stored as JSON - it's a list, join it with commas - which is right for a Checkboxes answer (["Red","Blue"] β†’ Red, Blue) and wrong for this:

// includes/services/forms.php - FormsService::submitForm(), before
$decoded = json_decode($value, true);
$flat = is_array($decoded) ? implode(', ', $decoded) : $value;

implode() does not care that one value is a number and the other a name. Out came 276, Ciara Doherty.

It was two places, not one

The same flattening lives in two files, because a form's answers reach rules on two roads:

Road Where Events
The form is sent FormsService::submitForm() form.submitted, catalogue_request.submitted
An approver decides catalogueAnswerText() via catalogueSubmissionAnswerMap() catalogue_request.approved / rejected / cancelled

Both had the identical implode. Fixing only the first would have left an approval-gated form saying 276, Ciara Doherty the moment its approver said yes - the kind of bug that looks fixed in testing because the test form has no approval step.

The fix

1. A lookup reads as its label

// includes/services/forms.php
public static function lookupAnswerText(?string $raw): string
{
    $d = json_decode((string)$raw, true);
    if (is_array($d) && array_key_exists('label', $d)) return (string)$d['label'];
    return (string)$raw;
}

catalogueAnswerText() gained the same rule for 'lookup'. {{submission.fields.Person}} now says Ciara Doherty.

2. The picked record travels with the submission

The label alone still cannot give you an email address. So every lookup answer also goes into a second map, submission.lookups, keyed by the question's label:

"submission": {
  "fields":  { "Person": "Ciara Doherty" },
  "lookups": { "Person": { "id": 276, "label": "Ciara Doherty", "source": "user",
                           "email": "...", "username": "...", "employee_id": "...",
                           "job_title": "...", "department": "...", "office": "...",
                           "phone": "...", "mobile": "..." } }
}

So {{submission.lookups.Person.email}} is the person's email, read from their record when the form was sent. What each kind of record brings is one list, FormsService::LOOKUP_DETAIL_COLS:

Lookup over Merge codes (all also have .id and .label)
People .email .username .display_name .preferred_name .employee_id .job_title .department .office .phone .mobile
Companies .name .ticket_code .external_ref .tax_id
Assets .hostname .asset_tag .service_tag
Consumables .name .part_number
Infrastructure, Locations .name

Why a second map and not submission.fields.Person.email? One merge code cannot be both a piece of text and a record with parts: fields.Person has to stay Ciara Doherty for every rule that already writes Hello {{submission.fields.Person}}. The reporter suggested the fields shape; lookups is the same idea without breaking what already works.

3. "The requester is the person picked in…"

Merge codes are the answer for webhooks, but a form designer should be able to choose this, not type it. So Raise a ticket in a form's What happens next has a new dropdown, Requester is the person picked in, listing that form's own pick a person questions:

// includes/catalogue_approvals.php - catalogueCreateTicketFromSubmission()
$pickedId = (int)($overrides['requester_user_id'] ?? 0);
if ($pickedId > 0) {
    ...
    $userId = $pickedId;
}

The designer's choice wins over whoever filled the form in: someone asking on behalf of a colleague is not the one with the problem. Picking a person does nothing on its own - Please select your favourite colleague stays just an answer, because nobody chose it in that dropdown.

The Workflows canvas does not show this dropdown - a workflow has no form to list questions from (the arg is marked forms_only) - and uses {{submission.lookups.<question>.email}} in Requester email instead.

A second, smaller bug found on the way

The demo ticket's preview in the Tickets list read This is what &quot;what happens next&quot;.... Previews are made by strip_tags(), which removes tags but leaves entities, and the list then escapes the text again. Four places did it - forms, new tickets, IMAP and Gmail - and all four now decode after stripping, the way the Knowledge previews already did (#3111).

How it was verified

  • tests/forms-lookup-answer-text.php - the label comes out, a label containing a comma survives whole, and Checkboxes still join with commas (the control: the rule that was wrong for lookups is right for them).
  • End to end on a demo form, picking only a dummy person: the payload carried "Person": "ZZ Demo Requester" and lookups.Person.email, and the ticket was raised with the picked person as its requester.
  • The forms editor showed the new dropdown with the form's Person question in it.

Not proven: a lookup over Companies or Assets end to end - the code path is the same column read, but only People was run.

What this means for you

  • A rule that used {{submission.fields.<lookup question>}} now gets the name. If you were cutting the number off the front in a webhook, use {{submission.lookups.<question>.id}} instead.
  • To raise a ticket for the person picked on a form: Forms β†’ edit the form β†’ What happens next β†’ Raise a ticket β†’ Requester is the person picked in β†’ your question.

Related

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally