locked
How to tell in javascript (from Item Tap) what item has been selected RRS feed

  • Question

  • Hi,

    I have a LS 2013 project where I need to call different browse screen depending upon the row selected. I can see that I can write some JavaScript to control this, I can call the relevant screen by:

    myapp.showBrowseLightswitchIDKey() (where BrowseLightswitchIDKey is my screen name)

    How can I determine which row was selected so that I can call the relevant screen?

    i.e. select case selecteditem

    case x: myapp.showbrowselightswitchidkey

    case y: myapp.showAnotherScreen

    etc

    Thanks,

    Steve

    Friday, January 10, 2014 1:03 PM

Answers

  • Steve,

    The exact code depends on where you will execute the script.  Is it a command bar button?  A button on each row, etc.

    Something like this may work (air code not tested):

    myapp.BrowseMyEntities.MyMethod_Execute = function (screen) {
        if (screen.MyEntities.selectedItem)
           {
           var item = screen.MyEntities.selectedItem;
           if ( item.SomeProperty == "SomeValue")
              {
              myApp.showSomeScreen();
              }
            if ( item.SomeProperty == "AnotherValue")
              {
              myApp.showAnotherScreen();
              }      
           } 
    };

    UPDATE---
    Sorry I missed '(from Item Tap)' in your title.  You need to execute a custom method on item tap then use code similar to above.

    HTH,

    Josh


    Friday, January 10, 2014 3:54 PM

All replies

  • Steve,

    The exact code depends on where you will execute the script.  Is it a command bar button?  A button on each row, etc.

    Something like this may work (air code not tested):

    myapp.BrowseMyEntities.MyMethod_Execute = function (screen) {
        if (screen.MyEntities.selectedItem)
           {
           var item = screen.MyEntities.selectedItem;
           if ( item.SomeProperty == "SomeValue")
              {
              myApp.showSomeScreen();
              }
            if ( item.SomeProperty == "AnotherValue")
              {
              myApp.showAnotherScreen();
              }      
           } 
    };

    UPDATE---
    Sorry I missed '(from Item Tap)' in your title.  You need to execute a custom method on item tap then use code similar to above.

    HTH,

    Josh


    Friday, January 10, 2014 3:54 PM
  • Hi,

    Thanks for the suggestion, I have tried this and cannot find any kind of 'select item' property.

    I was using 'on tap' on the row, however a button on each row would equally work as well. I have just added this however I have the same issue, I need to tell which row the button was on. Or is it possible to add a differently named button to each row? (as that would also resolve the issue).

    Thanks,

    Steve

    Monday, January 13, 2014 12:05 PM
  • Hi Steve,

    The following should return the selected item (where 'MyEntities' is the plural name of the collection on the screen.

    screen.MyEntities.selectedItem;

    So if your entity is called 'Customer' with a plural form 'Customers' it would be:

    screen.Customers.selectedItem;

    Please know that intellisense sometimes doesn't work so you just have to try it.  If you still need help then share your code and let us know what kind of screen your using (ie : browse screen, search screen, etc)

    HTH,

    Josh

    • Proposed as answer by joshbooker Monday, January 13, 2014 2:59 PM
    Monday, January 13, 2014 1:45 PM
  • Hi Josh,

    That works!! Thanks very much for your help, I will continue my development project and no doubt post another question when I get stuck again ....

    Cheers,

    Steve

    Monday, January 13, 2014 2:55 PM