Page 1 of 1

Default value in select object

Posted: Thu Apr 03, 2025 5:52 pm
by yvesf
Hi,

I have a select object "prat_acc" in which I would like to retrieve the list of users.
I have behind the select the following code

Code: Select all

SELECT
 zzzzsys_user.sus_zzzzsys_access_id,
    zzzzsys_user.sus_name

FROM
    zzzzsys_user
It lists the users declared in the application. It works perfectly !!! (except I have null corresponding to globeadmin user).
I would like to put a default value and behind the nuload event of "prat_acc" object I have :

Code: Select all

 if (nuAccessLevelCode() === 'praticien') {
  nuSetValue('prat_acc', nuUserId());
It doesn't work probably because it is a select object which needs to have 2 values and not only one. How can I solve that ?
Many thx,

Yves

Re: Default value in select object

Posted: Thu Apr 03, 2025 7:07 pm
by kev1n
You can adjust your select query by using a UNION to add a default value for the "globeadmin" user.

Code: Select all

SELECT
    zzzzsys_user.sus_zzzzsys_access_id,
    zzzzsys_user.sus_name
FROM
    zzzzsys_user
WHERE
    zzzzsys_user.sus_name IS NOT NULL

UNION

SELECT
    '0' AS sus_zzzzsys_access_id, 
    'globeadmin' AS sus_name

Re: Default value in select object

Posted: Thu Apr 03, 2025 9:36 pm
by yvesf
Thanks Kev1n.
I'd like to set the default value to the currently connected user — but only if they belong to the praticien access control group (not just globeadmin).
Using UNION is an interesting idea I hadn't thought of. Here is the final code

Code: Select all

SELECT
    zzzzsys_user.zzzzsys_user_id,
    zzzzsys_user.sus_name
FROM
    zzzzsys_user
WHERE
    zzzzsys_user.sus_name IS NOT NULL

UNION

SELECT
    'globeadmin' AS zzzzsys_user_id, 
    'globeadmin' AS sus_name
And what about default value of a select object when defined by an sql query ??
Yves

Re: Default value in select object

Posted: Thu Apr 03, 2025 10:11 pm
by kev1n
nuSetValue('prat_acc', 'globeadmin'); ?

Re: Default value in select object

Posted: Fri Apr 04, 2025 2:38 am
by yvesf
    Kev1n,


    It's exactly what I did behind the onnuload event and it doesn't work unfortunately. Except it wasn't globe admin as default value but the current connected user. The code is

    Code: Select all

    if (nuAccessLevelCode() === 'praticien') {
      nuSetValue('prat_acc', nuUserId());
      }
    Functionally speaking, it is very common to be interested to have the current connected user as default value when leveraging the access roles provided by nubuilder. How can you implement that in a select field using an SQL query ?
    Many thx in advance for your help.

    Yves

    Re: Default value in select object

    Posted: Fri Apr 04, 2025 5:41 am
    by kev1n
    It looks like your JavaScript code is missing a closing curly brace (}) for the if statement.