Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Default value in select object Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
yvesf
Posts: 305
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 83 times
Been thanked: 11 times

Default value in select object

Unread post 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
kev1n
nuBuilder Team
Posts: 4242
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 68 times
Been thanked: 422 times
Contact:

Re: Default value in select object

Unread post 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
yvesf
Posts: 305
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 83 times
Been thanked: 11 times

Re: Default value in select object

Unread post 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
kev1n
nuBuilder Team
Posts: 4242
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 68 times
Been thanked: 422 times
Contact:

Re: Default value in select object

Unread post by kev1n »

nuSetValue('prat_acc', 'globeadmin'); ?
yvesf
Posts: 305
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 83 times
Been thanked: 11 times

Re: Default value in select object

Unread post 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
    Last edited by yvesf on Fri Apr 04, 2025 8:42 am, edited 1 time in total.
    kev1n
    nuBuilder Team
    Posts: 4242
    Joined: Sun Oct 14, 2018 6:43 pm
    Has thanked: 68 times
    Been thanked: 422 times
    Contact:

    Re: Default value in select object

    Unread post by kev1n »

    It looks like your JavaScript code is missing a closing curly brace (}) for the if statement.
    Post Reply