Setting a default value to a modal picker on a detail screen in the screen created (HTML Client) RRS feed

  • General discussion

  • Hi,

    Would like to share a bit of code where you can set a default value to a local property (picker) Entity.

    I have a screen (detail screen). I navigate to this screen with a click of a button.

    I don't want to use a list where I have to choose a customer. I would like to pick a customer from a Modal picker.

    This is not a problem. I choose a table (customer, single or default (shows only one entity)).

    By choosing this I get a parameter (Id).

    I choose a local property (Customer(Entity) and bind the Id to the Entity.Id.

    I then pick a new Query from "Add Data Item". CustomersQuery or the Query you set up.

    When I navigate to the screen I have to choose a customer from the Modal picker. It's okey but I want to populate the modal picker with the first entity from customers.

    Hmmmm. Not so easy. Ok

    In the screen created method I put this code. The code will load the first entity in the Collection an set the value to the Modal picker.

    myapp.CustomerSceen.created = function (screen) {
        // Write code here.
        setTimeout(function () {
                var visualCollection = screen.CustomersQuery;
                if (visualCollection.isLoaded) {
                    var default = visualCollection.data[0];
                    screen.KundEntity = default;
                } else {
                    visualCollection.addChangeListener("isLoaded", function () {
                        var default = visualCollection.data[0];
                        screen.CustomerModalPicker = default;
        }, 0);

    Easy! Enjoy

    Regards Sven

    Sven Elm

    • Edited by Sven Elm Wednesday, August 20, 2014 4:19 PM
    Wednesday, August 20, 2014 4:18 PM