locked
Conditional Navigation to Screen from Code (HTML) RRS feed

  • Question

  • Hello,

    i have a list of items and would like to go to different screens based on values in the item.

    Any help would be much appreciated!


    Friday, April 8, 2016 4:57 PM

Answers

  • Hi silva71,

    Thanks for your response and the detailed description.

    According to your description, I create a browser screen for Task table and then set the Item list as Title List which is shown as below image.

    Then I choose the custom method for the Item Tap property and add my custom code to navigate to the assigned screen based on the condition. The code is similar as following.

    myapp.BrowseTasks.Task_ItemTap_execute = function (screen) {
        // The getVisit() method can return the object of Visit for current selected Task object    
        if (screen.details.properties.Tasks.value.selectedItem.getVisit() == null) {
            myapp.showViewTask(null, {
                beforeShown: function (addNewScreen) {
                    var task = new myapp.Task();
    
                    addNewScreen.Task = task;
                }
            });
        }
        else {
            // Navigate to another screen
            myapp.showViewVisit(null, {
                beforeShown: function (addNewScreen) {
                    var visit = new myapp.Visit();
    
                    addNewScreen.Visit = visit;
                }
            });
        }
    
    };


    Best Regards,
    Weiwei


    Tuesday, April 12, 2016 9:03 AM
    Moderator
  • Found the solution,

    myapp.BrowseTasks.Tasks_ItemTap1_execute = function (screen) {
        // Write code here.
        var selectedItem = screen.Tasks.selectedItem;
        if (selectedItem.Visit) {
            myapp.showViewVisit(
                selectedItem.Visit);
        } else  {
            myapp.showViewTask(
                selectedItem);
        }
    };
    Thanks!

    • Marked as answer by silva71 Tuesday, April 12, 2016 3:39 PM
    Tuesday, April 12, 2016 3:38 PM

All replies

  • Hi Angie,

    can you please help me on this?

    thank you so much

    Monday, April 11, 2016 9:19 AM
  • Hi silva71,

    Where is the list of items in your application? And how do you want to navigate to different screens, through a button, a dropdown list or any other controls?

    Please tell us the detailed information about your process, which can help understanding your requirement and find out how to implement your requirement quickly.

    For example, if you want to navigate through a button based on some items, please try with following code.

    myapp.AddEditDevice.AddRepair_execute = function (screen) {
        if (your condition) {
            myapp.showAddEditRepair(null, {
                beforeShown: function (addNewScreen) {
                    var repair = new myapp.Repair();
    
                    addNewScreen.Repair = repair;
                }
            });
        }
        else if (your condition) {
           // Navigate to another screen
        }
        else {
          // Navigate to another screen
        }
    
    };

    Best Regards,
    Weiwei

    Monday, April 11, 2016 9:44 AM
    Moderator
  • Hi Weivei,

    thank you so much for your reply.

    I would like to do the following:

    1) I have a Task table and a Visit Table. Task table can have a Visit (0..1 relation) 

    2) I have a grid BrowseTask 

    3) If VisitId is not null navigate to ViewVisit 

    4) If VisitId is null navigate to ViewTask

    I think I need a custom Tap method.

    Thank you so much

    Monday, April 11, 2016 9:56 AM
  • Hi silva71,

    Thanks for your response and the detailed description.

    According to your description, I create a browser screen for Task table and then set the Item list as Title List which is shown as below image.

    Then I choose the custom method for the Item Tap property and add my custom code to navigate to the assigned screen based on the condition. The code is similar as following.

    myapp.BrowseTasks.Task_ItemTap_execute = function (screen) {
        // The getVisit() method can return the object of Visit for current selected Task object    
        if (screen.details.properties.Tasks.value.selectedItem.getVisit() == null) {
            myapp.showViewTask(null, {
                beforeShown: function (addNewScreen) {
                    var task = new myapp.Task();
    
                    addNewScreen.Task = task;
                }
            });
        }
        else {
            // Navigate to another screen
            myapp.showViewVisit(null, {
                beforeShown: function (addNewScreen) {
                    var visit = new myapp.Visit();
    
                    addNewScreen.Visit = visit;
                }
            });
        }
    
    };


    Best Regards,
    Weiwei


    Tuesday, April 12, 2016 9:03 AM
    Moderator
  • Hi Weiwei,

    thank you so much for your feedback.

    I think your code is almost perfect since:

    screen.details.properties.Tasks.value.selectedItem.getVisit()

    always return an object so it's never null.

    The result of your code is always:

    It always shows the ViewVist Page without any selectedItem.

    This is what I want to accomplish: Browse Task 

    When the first Row is selected Task Test, Visit is null and would like to be redirected to the ViewTask Page:

    When the Visit Test row is selected (Visit is not null) go to the ViewVisit Page:

    Can you please help me on this, I think with your suggestion we are really close!

    Tuesday, April 12, 2016 2:59 PM
  • Found the solution,

    myapp.BrowseTasks.Tasks_ItemTap1_execute = function (screen) {
        // Write code here.
        var selectedItem = screen.Tasks.selectedItem;
        if (selectedItem.Visit) {
            myapp.showViewVisit(
                selectedItem.Visit);
        } else  {
            myapp.showViewTask(
                selectedItem);
        }
    };
    Thanks!

    • Marked as answer by silva71 Tuesday, April 12, 2016 3:39 PM
    Tuesday, April 12, 2016 3:38 PM