1

Next Record On List Dialog

I am trying to get next item from list dialog via json file, working fine if record not found or single record, issue comes when there are multiple records found and i get list dialog with record 1 of 10, 2 of 10, 3 of 10, and so on for 10 records found but list record is not changing i.e. fist record only appearing while all other changes. my code 

Task: Search Contact2

    

    A1: Input Dialog [

         Title: SEEPCO

         Text: Enter name, email, ID, etc.

         Close After (Seconds): 30

         Input Type: text

         Output Variable Name: %search_term ]

    

    A2: Read File [

         File: Tasker/profiles/Seepcocontact.json

         To Var: %json_data

         Structure Output (JSON, etc): On ]

    

    A3: JavaScriptlet [

         Code: var data = JSON.parse(local('json_data'));               var term = local('search_term');               if (!term) {                   setLocal('results', '[]');                   setLocal('result_count', 0);               } else {                   term = term.trim().toLowerCase();                   var matches = data.filter(person =>                       (person.Name && person.Name.toLowerCase().includes(term)) ||                       (person.Email && person.Email.toLowerCase().includes(term)) ||                       (person.ID && person.ID.toLowerCase().includes(term)) ||                       (person['Member ID'] && person['Member ID'].toString().includes(term)) ||                       (person['IP Number'] && person['IP Number'].toString().includes(term)) ||                       (person.Mobile && person.Mobile.toString().includes(term))                   );                   setLocal('results', JSON.stringify(matches));                   setLocal('result_count', matches.length);               }               setGlobal('CURINDX', 1);

         Auto Exit: On

         Timeout (Seconds): 45 ]

    

    A4: Flash [

         Text: 4, %CURINDX, %result_count

         Continue Task Immediately: On

         Dismiss On Click: On ]

    

    A5: Variable Set [

         Name: %result_count

         To: %result_count

         Do Maths: On

         Max Rounding Digits: 0

         Structure Output (JSON, etc): On ]

    

    A6: List Dialog [

         Mode: Select Single Item

         Title:  

         Items: Not Found 😓

         Close After (Seconds): 5

         First Visible Index: 0

         Hide Filter: On

         Text: You Searched for %search_term !

         Continue Task After Error:On ]

        If  [ %result_count < 1 ]

    

    A7: JavaScriptlet [

         Code: var matches = JSON.parse(local('results'));                   var person = matches[0];                   var displayText = "Name: " + (person.Name || 'N/A') + "\n" +                                     "Email: " + (person.Email || 'N/A') + "\n" +                                     "Mem. ID: " + (person['Member ID'] || 'N/A') + "\n" +                                     "IP #: " + (person['IP Number'] || 'N/A') + "\n" +                                     "Mobile: " + (person.Mobile || 'N/A');                   setLocal('display_text', displayText);

         Auto Exit: On

         Timeout (Seconds): 45 ]

    

    A8: Flash [

         Text: 8,  %CURINDX, %result_count

         Continue Task Immediately: On

         Dismiss On Click: On ]

    

    A9: Variable Set [

         Name: %display_position

         To: %CURINDX

         Do Maths: On

         Max Rounding Digits: 0

         Structure Output (JSON, etc): On ]

    

    A10: List Dialog [

          Mode: Select Single Item

          Title: Contact (%display_position of %result_count !)

          Items: %display_text

          Button 3: ❎

          Close After (Seconds): 10

          First Visible Index: 0

          Hide Filter: On ]

        If  [ %result_count = 1 ]

    

    A11: If [ %result_count > 1 ]

    

        <A12>

        A12: JavaScriptlet [

              Code: // A12: JavaScriptlet

             // Code:

             var matches = JSON.parse(local('results')); // Parse the search results array

             

              

             

             // Get the current 1-based index from global variable, default to 1 if not set

             var currentGlobalIndex = parseInt(global('CURINDX')) || 1;

             

              

             

             // Ensure the index is within the valid range [1, matches.length]

             if (currentGlobalIndex < 1) {

                 currentGlobalIndex = 1; // Reset to first if somehow less than 1

             } else if (currentGlobalIndex > matches.length) {

                 currentGlobalIndex = matches.length; // Reset to last if somehow greater than total

             }

             

              

             

             // Update the global CURINDX to reflect any corrections made above

             setGlobal('CURINDX', currentGlobalIndex);

             

              

             

             // Convert the 1-based currentGlobalIndex to a 0-based JavaScript array index

             var arrayIndex = currentGlobalIndex - 1;

             

              

             

             var person = matches[arrayIndex]; // Get the person object at the calculated index

             

              

             

             // Construct the display text using the person object's properties

             var displayText = "Name: " + (person.Name || 'N/A') + "\n" +

                               "Email: " + (person.Email || 'N/A') + "\n" +

                               "Mem. ID: " + (person["Member ID"] || 'N/A') + "\n" +

                               "IP #: " + (person["IP Number"] || 'N/A') + "\n" +

                               "Mobile: " + (person.Mobile || 'N/A');

             

              

             

             setLocal('display_text', displayText); // Set local variable for Tasker to use

             setLocal('current_index_for_display', currentGlobalIndex); // Optional: for debugging/display

              Auto Exit: On

              Timeout (Seconds): 45 ]

    

        A13: Flash [

              Text: 13,  %CURINDX

              Continue Task Immediately: On

              Dismiss On Click: On ]

    

        A14: Variable Set [

              Name: %display_position

              To: %CURINDX

              Do Maths: On

              Max Rounding Digits: 0

              Structure Output (JSON, etc): On ]

    

        A15: List Dialog [

              Mode: Select Single Item

              Title: Contact (%display_position of %result_count !)

              Items: %display_text

              Button 1: ➡️

              Button 2: ⬅️

              Button 3: ❎

              Close After (Seconds): 10

              First Visible Index: 0

              Hide Filter: On ]

    

        A16: If [ %ld_button ~ ➡️ ]

    

            A17: Variable Add [

                  Name: %CURINDX

                  Value: 1

                  Wrap Around: 0 ]

    

            A18: Flash [

                  Text: 18,  %CURINDX

                  Continue Task Immediately: On

                  Dismiss On Click: On ]

    

            A19: If [ %CURINDX > %result_count ]

    

                A20: Variable Set [

                      Name: %CURINDX

                      To: 1

                      Do Maths: On

                      Max Rounding Digits: 0

                      Structure Output (JSON, etc): On ]

    

                A21: Flash [

                      Text: 20,  %CURINDX

                      Continue Task Immediately: On

                      Dismiss On Click: On ]

    

            A22: End If

    

            A23: Goto [

                  Type: Action Label

                  Label: A12 ]

    

        A24: End If

1 reply

Can you please clarify what you mean by "next item from list dialog"? Thanks