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
  • I agree with what others have said about why this happens, but in general I would suggest keeping the return type as a list if it can return a variable number of results. In some cases it can actually make it harder to manage if your return type is sometimes a list or sometimes a single item. However, if it's always a list (even if it's a list of one or zero), then it's easier to troubleshoot issues and design in a way that lists are supported.

    The case to me where it does make sense to cast it to a single item (like Mike suggested) is when you know it will always return a single item (or null). For example, if you have a query that filters by the primary key, it's guaranteed to only return a single item, so you might as well cast the type to a single item as well.

Reply
  • I agree with what others have said about why this happens, but in general I would suggest keeping the return type as a list if it can return a variable number of results. In some cases it can actually make it harder to manage if your return type is sometimes a list or sometimes a single item. However, if it's always a list (even if it's a list of one or zero), then it's easier to troubleshoot issues and design in a way that lists are supported.

    The case to me where it does make sense to cast it to a single item (like Mike suggested) is when you know it will always return a single item (or null). For example, if you have a query that filters by the primary key, it's guaranteed to only return a single item, so you might as well cast the type to a single item as well.

Children
No Data