WebHare community

Getting results from forms

At the moment, when we need results form a form, it goes something like this, assuming I want the value of the “Description” question:

OBJECT formresults := OpenFormFileResults(OpenWHFSObject(issues.form.internallink));
RECORD singleresult := formresults->GetSingleResult(resultguid);
RECORD resultdata := formresults->GetWittyResultdata(singleresult);
RETURN SELECT AS STRING text FROM resultdata.allfields WHERE ToUpperCase(fieldname) = "DESCRIPTION";

I can’t imagine there’s not a better solution for this :slight_smile:

(Looping in @Anferney)

Looks good to me ? What did you expect?

I don’t expect that approach to be doing any unnecessary database traffic and it properly shows the granularity. (eg you can’t access individual answers of a result efficiently, so we don’t provide an ‘outputcolumns’ like parameter)

I guess you could skip the GetWittyResultdata but then you’d have to work out the proper presentation of a field yourseflf.

It just seemed a bit inefficient to me. Also usng a function called GetWittyResultdata when I don’t want Witty data but just the results with their titles and values seems a bit off.

Perhaps some combination function of GetSingleResult and GetWittyResultdata would make sense, to get a (more readable) result array. Or an option added to GetSingleResultById which makes it return GetWittyResultdata.allfields?

Apart from this, I see I could’ve written it like this because I’m getting a tagged question value:

OBJECT formresults := OpenFormFileResults(OpenWHFSObject(issues.form.internallink));
RECORD singleresult := formresults->GetSingleResult(resultguid);
RETURN singleresult.response.description;

(omitting some *Exists functions)

Also one less function!

That’s one possible API change

And now we have at least two alternative ways to define this API, and neither is any faster than the original. I’m not sure what metric you use to declare either ‘more efficient’.

But unless a change to an API actually allows significantly easier or faster access to the data, all you’re doing is increasing complexity by adding more ways to do the same thing. Beside, the form results API weren’t designed to be fast, they were designed to be flexible. It’s the only API that lets the end user decide on the form of the data (by modifying the questions) while still allowing structured access (eg all data is accessible using a XLSX export). None of the other storage APIs in WebHare can do this.

But if you’re looking for fast access to the stored data, this API is not for that.