152
Views
1
Comments
Solved
Why the static entity records are not appearing?
Question

I have a static entity MovieGenre. There are some movie genres, the MovieGenre static entity has an attribute "CompanyId" (The Company is also a static entity and there are 4 records in this static enttiy), for some MovieGenres the attribute has a CompanyId for other genres the CompanyId is null like:

Identifier Comedy
Label "Comedy"
CompanyId (dont have nothing because is null)

Now in a query I have a session variable CompanyId as input parameter and:
- I want to show the movie genres records of the movie if the CompanyId session variable is not null
- but if the ComapnyId is null I want to show the records of the static entity MovieGenre that have the CompanyId null (empty)

So in the query I have as parameter the CimoanyId and the conditions I have:

MovieGenre.CompanyId = CompanyId

But its not working properly if the CompanyId session variable is not null it works correctly, but if the CompanyId is null the query is not returning any results, but it should return the records that have the CompanyId as null.

Do you know why its not working?

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Oscar,

This has to do with the fact you can't compare NULL values in a database. That has nothing to do with OutSystems, but with the way SQL databases work. So if you want to get the right record in case both MovieGenre.CompanyId is NULL and CompanyId is NULL, you need the following Filter:

MovieGenre.CompanyId = CompanyId or (MovieGenre.CompanyId = NullIdentifier() and CompanyId = NullIdentifier())

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.