Question

Custom Entity - Yes or No

  • 15 January 2024
  • 5 replies
  • 70 views

Userlevel 2
Badge +6

I’ve created a custom entity that has some SQL behind it that results in “0” or Greater than “0” as the output. 

If it’s zero, I want the field to say “False” and if it’s not zero, it would say “True”.

What’s the best way to achieve this?


5 replies

Userlevel 2
Badge +9

Hi @dfsjmarchant

I'm unsure if this will completely cover every situation. I will describe 2 options.

Option 1:

If you want to stick to the 0/1:

I'm assuming that there will only be 2 statusses:

0 (false) and 1 (true).

  1. I would recommend creating a custom enumeration where db value = 0/1  and description is false/true
  2. Go to custom entity and press +  create a persistent field with type enumeration and select the custom enumeration. Use the switch boolean To determine which value is true and which value is false

 

Option 2:

If you don't specifically want to stick to the 0/1 statusses. There is a standard enumeration Named FndBoolean which contains True/False value.

  1. Go to custom entity and press +  create a persistent field with type enumeration and select the enumeration FndBoolean . Use the switch boolean To determine which value is true and which value is false
Userlevel 2
Badge +6

Thanks for that, good response. I’ve tested that and it works OK. 

I’ve heard that it’s possible to use a case statement too, would that be easy to achieve? In future I may have another scenario where I can’t use an enumeration. 

So it would be something like, “SELECT…” if result is <1 then return “Inactive” ELSE “Active”.

I’m just not sure how to construct it.

 

Userlevel 2
Badge +9

Hi @dfsjmarchant,

 

It depends. If it is based on a diferent field that would be possible too. In that case you would have to create a read only field and the query would be 

SELECT CASE WHEN :VARIABLE > 0 THEN ‘TRUE’ ELSE ‘FALSE’ END FROM DUAL 

This is a dummy statement where you would have to replace the variable with your variable,

The argument is the column which is the field containing the 0/1. the argument could be v.customer_no (example). then the query would be “SELECT CASE WHEN :CUSTOMER_NO > 0 THEN ‘TRUE’ ELSE ‘FALSE’ END FROM DUAL “

 

Userlevel 2
Badge +9

@dfsjmarchant , Did you manage to work out the details of your specific scenario?

Userlevel 2
Badge +6

Hi, 

Yes, thanks. I’ve achieved it like this…

SELECT CASE        WHEN isvalid = 1        THEN 'Yes'        ELSE 'No'        END AS RESULTS FROM   (   SELECT       ( COUNT(supplier_id) ) isvalid    FROM       supplier_info_address    WHERE       sysdate BETWEEN valid_from AND valid_to       AND supplier_id = :supplier_id )

Thanks for your help :)

Reply