Forum Stats

  • 3,874,331 Users
  • 2,266,724 Discussions
  • 7,911,822 Comments

Discussions

How to add an entry into a Select List programmatically? (Apex 19.2)

John like many others
John like many others Member Posts: 116 Blue Ribbon
edited Nov 19, 2020 1:17PM in APEX Discussions

Hello

I would like to add a new entry into an existing select list (with existing entries) programmatically (Javascript). The most obvious way would be:

apex.item( "MYSELECTLIST" ).addValue( "mydisplaytext", 100 );

or maybe the other way around:

apex.item( "MYSELECTLIST" ).addValue( 100, "mydisplaytext" );

Both ends up with: desktop_all.min.js?v=19.2.0.00.18:5 No default handling defined for addValue

I coudln't find a clear/proper example for adding an entry into a SELECT List in the Apex documentation and the Internet.

Anyone has an idea how to add an entry into a Select List ?

Best Answer

Answers

  • jflack
    jflack Member Posts: 1,524 Bronze Trophy

    I'm with @InoL - if you do this in JavaScript, the change is only effective while you are still on the page. So suppose a new value is added to the select list, and the user selects the new value. The next time you view that data, or when the data is viewed in another session, there will be no match anymore. If you want the change to be saved, I'd advise that the LOV be generated from a SELECT. Then, if it comes from a reference table, you can write a PL/SQL dynamic action to add a row to the table. Or if there are conditions whether the select item should be shown, then you could write it as a cascading LOV and add variables to the SELECT.

  • John like many others
    John like many others Member Posts: 116 Blue Ribbon

    Thank you both.

    In short: Apex forces me to. If I could have it easy and simple I'd prefer that.

    In long: The reason why I need this that I add a value in the background (in DB) that affects the Select List (additional entry). I need that value in the Select List (programmatically as well) so then a page reload will be executed and the previously set value will be displayed (the one stored in DB = the set one in the Select List). If I don't do that then not the latest DB entry is shown in the list but the one the user has previously selected.

    Ok, got it, Apex does not provide a function to add a new element into a Select List, I need to do it with JQuery and addValue on Select List is misleading (missed this in Apex documentation).

    Ok, tried with JQuery and it works like a charm, thank you!

  • InoL
    InoL Member Posts: 10,202 Blue Diamond

     I add a value in the background (in DB) that affects the Select List (additional entry).

    So, if some other process or user adds, e.g., a new DEPT, you want that reflected in the DEPT LOV? That is not possible without a refresh. There is no way for the page to know that in the mean time a new DEPT was created in the database (unless you have some push notification or polling mechanism).

    John like many others
  • John like many others
    John like many others Member Posts: 116 Blue Ribbon

    Good point... The procedure adding the "new DEPT" is a DB procedure. So when user A creates a LOV entry user B might not see it on same mask/record opened (very unlikely) until page refresh, that's not nice but also not that bad. If user B tries to create a new DEPT (while not seeing the new DEPT entry from user A the DB procedure (called from Apex) would block that. Why? :

    "New DEPT" is in real a version (snapshot) of the current data state. To create a new version a user has to set a non overlapping time range (to other versions). So when user B wants to save his version it would overlap with the new version of user A and get informed about that.