Query data

Hi Everyone,

I am querying the db table through query record type. This query gives the list of db records. When I am using this in interface and using index to get the particular field, it gives this list of particular field. In case of null or single it also gives list. Can anyone please help me when it is null or single value should not give list.

  Discussion posts and replies are publicly visible

Parents
  • Queried data (of any type, be it record type or entity) is automatically treated as a list (whether single, empty, or list) until you specify otherwise.

    A common way of forcing the output to appear as single is to use the square bracket indexing to specify the first result (which is necessary even if there's only one) - like [1] after ".data" (being the result of your query).  One issue this creates is it'll break (error) if the query actually returns empty - so instead we use index() for what it's intended for, i.e. to grab the first index (if any) and specify a default value otherwise...

    index(local!myQueryResult.data, 1, {})  (note: you should replace "{}" here with "null()" to force the output to show up as simply blank instead of an empty list, if desired)

    and, as always, to avoid confusion and increase code readability, i strongly suggest that you use property() to retrieve a specific field instead of index(), since "index" implies a position in an array, and "property" implies a particular data property.

    As Konduru mentioned already, sharing a code snippet and/or result screenshots would help us specify what you'd need to do in your particular case.

  • Hi , As per above, I am not sure if .data in recordtype will be supported. .data gives error "can only be indexed using square brackets" when there is one record in output. And if indexed using square brackets then it gives error "invalid index" when output is null.

  • without seeing what exactly you're trying and what exactly your query output / error is, it's hard to say, but i'm guessing you're mixing up indexing (in terms of array position) with trying to fetch the record type property (which needs to be fetched not with a dot property but either with square brackets that contain the record property reference, or in the "property()" function where the record type property reference is passed instead of the plaintext field name).

Reply
  • without seeing what exactly you're trying and what exactly your query output / error is, it's hard to say, but i'm guessing you're mixing up indexing (in terms of array position) with trying to fetch the record type property (which needs to be fetched not with a dot property but either with square brackets that contain the record property reference, or in the "property()" function where the record type property reference is passed instead of the plaintext field name).

Children
No Data