locked
Set Default Value in Auto Filled ComboBox RRS feed

  • Question

  • Hello,

    I'm new to LS i have a very simple problem.

    I have a Name Table, with a NameTypeID fields, the lookup Table NameType contains the following values:

    • 1 - Lead 
    • 2 - Customer
    • etc.

    I created a Query and called it Lead, that of course selects only Name where NamteTypeID is the Lead

    Then i created a Screen for the Lead.

    When adding a Lead i want the ComboBox NameType to have by default value Lead (NameTypeId = 1).

    I Know it should be something Like

    myapp.AddEditLeadsScreen.created = function (screen) {
        // Write code here.
        screen.Name.NameType = myapp.DataWorkspace...
        
    };

    But is not working for me...

    Thank you so much for help

     

     


    • Edited by silva71 Wednesday, November 5, 2014 6:37 AM
    Wednesday, November 5, 2014 6:36 AM

Answers

  • Hi, Silva!

    Maybe this similar code helps you:

    The example has two tables: Car (fields: Id, Model and Color) and Color (fields: Id and ColorName).

    When I registre a new car, I want to define a default color.

    myapp.AddEditCar.created = function (screen) {
        
        // The car's default color id
        var defaultColorId = 2;
    
        // note: 'ColorById' is a query with ColorId as parameter
        myapp.activeDataWorkspace.ApplicationData.ColorById(defaultColorId).execute().then(function (results) {
            // Check to see if any color is returned
            if (results.results.length >= 0) {
                // Find the default color
                var defaultColor = results.results[0];
                // Set the car's color field.
                screen.Car.setColor(defaultColor);
            };
        });
    };
    Best regards,



    Ciro

    • Marked as answer by silva71 Monday, November 10, 2014 2:25 PM
    Wednesday, November 5, 2014 11:32 PM

All replies

  • Please Anyone?
    Wednesday, November 5, 2014 8:55 PM
  • Hi, Silva!

    Maybe this similar code helps you:

    The example has two tables: Car (fields: Id, Model and Color) and Color (fields: Id and ColorName).

    When I registre a new car, I want to define a default color.

    myapp.AddEditCar.created = function (screen) {
        
        // The car's default color id
        var defaultColorId = 2;
    
        // note: 'ColorById' is a query with ColorId as parameter
        myapp.activeDataWorkspace.ApplicationData.ColorById(defaultColorId).execute().then(function (results) {
            // Check to see if any color is returned
            if (results.results.length >= 0) {
                // Find the default color
                var defaultColor = results.results[0];
                // Set the car's color field.
                screen.Car.setColor(defaultColor);
            };
        });
    };
    Best regards,



    Ciro

    • Marked as answer by silva71 Monday, November 10, 2014 2:25 PM
    Wednesday, November 5, 2014 11:32 PM
  • Dear Ciro,

    it works perfectly!

    Thank you so much!

    A very quick question following your example.

    In your Car Screen there is a Color ComboBox that is filled with data coming from the Color table.

    What if you want to fill the Color Combox with a Query from the Color Table? Where

    you can Add the Code, do you have a sample?

    Thank you so much

    --silvano

    Monday, November 10, 2014 2:34 PM