web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Automatically set sele...
Power Apps
Unanswered

Automatically set selected gallery item based on id.

(0) ShareShare
ReportReport
Posted on by 72

Hi,

I have a gallery which displays a collection of students that a music teacher teaches for the day in addition to groups they take. It is created using this code (called fnLoadLessons):

 

ClearCollect(
 colLessons,
 ForAll(
 Filter(
 Sort(
 InstrumentLessons,
 ID,
 SortOrder.Descending
 ), TeacherID = Text(varTeacher.ID), LessonDate = selectedDate
 ),
 {
 PupForm: LookUp(
 StudentCoreData,
 SchoolID = StudentID,
 Form
 ),
 PupSurname: LookUp(
 StudentCoreData,
 SchoolID = StudentID,
 Surname
 ),
 PupFirstName: (If(Len(StudentID) > 10, 
 LookUp(
 StudentCoreData,
 SchoolID = StudentID,
 'Preferred Name'),
 LookUp(
 InstrumentalGroups, 
 GroupID = StudentID,
 GroupName)
 )),
 TimePeriod: LookUp(
 InstrumentLessonTimePeriods,
 Text(TimeID) = LessonTimeID,
 Title
 ),
 TNotes: TeacherNotes,
 TNotesByT: NotesbyTeacher,
 Inst: Instrument,
 TimeID: Value(LessonTimeID),
 LessonID: ID,
 Present: HasArrived,
 Live: Published,
 AttendanceStat: Attendance,
 PupilID: StudentID
 }
 )
);
ClearCollect(
 colLessons,
 SortByColumns(
 colLessons,
 "TimeID",
 SortOrder.Ascending
 )
);

 

Currently the teacher selects the student, ticks a 'mark as present' box then presses a save button which runs this command:

SubmitForm(Form1); Set(varSelLesson, varSelectedLesson.LessonID);Select(fnLoadLessons);

 

The SubmitForm then updates the Sharepoint list but the teacher is then returned to the first person in the list.  I found that just having the SubmitForm didn't seem to give enough time for the sharepoint list to update so when they clicked on save the form would come back unticked unless they refreshed the page again hence why I've added the Select(fnLoadLessons) at the end. 

So my question is whether I can set the selected item in the gallery based on the varSelLesson variable.

 

Thank you for your help.

Categories:
  • anandm08 Profile Picture
    1,936 Super User 2024 Season 2 on at

    hi @rbjames ,

    Yes, you can set the selected item in the gallery based on the varSelLesson variable. You can achieve this by using the Select function on your gallery and passing the appropriate item from your data source based on the varSelLesson variable.

     

    ClearCollect(
     colLessons,
     ForAll(
     Filter(
     Sort(
     InstrumentLessons,
     ID,
     SortOrder.Descending
     ), 
     TeacherID = Text(varTeacher.ID), 
     LessonDate = selectedDate
     ),
     {
     PupForm: LookUp(
     StudentCoreData,
     SchoolID = StudentID,
     Form
     ),
     PupSurname: LookUp(
     StudentCoreData,
     SchoolID = StudentID,
     Surname
     ),
     PupFirstName: (If(Len(StudentID) > 10, 
     LookUp(
     StudentCoreData,
     SchoolID = StudentID,
     'Preferred Name'
     ),
     LookUp(
     InstrumentalGroups, 
     GroupID = StudentID,
     GroupName
     )
     )),
     TimePeriod: LookUp(
     InstrumentLessonTimePeriods,
     Text(TimeID) = LessonTimeID,
     Title
     ),
     TNotes: TeacherNotes,
     TNotesByT: NotesbyTeacher,
     Inst: Instrument,
     TimeID: Value(LessonTimeID),
     LessonID: ID,
     Present: HasArrived,
     Live: Published,
     AttendanceStat: Attendance,
     PupilID: StudentID
     }
     )
    );
    
    ClearCollect(
     colLessons,
     SortByColumns(
     colLessons,
     "TimeID",
     SortOrder.Ascending
     )
    );
    
    // Selecting the item based on varSelLesson
    Select(
     YourGalleryName,
     LookUp(colLessons, LessonID = varSelLesson)
    );

     

    Replace YourGalleryName with the name of your gallery control where you want to select the item. This code will set the selected item in the gallery to the item in your data source where the LessonID matches the varSelLesson variable.

  • rbjames Profile Picture
    72 on at

    Thanks - I've tried that but I get the error below:

    rbjames_0-1719320347472.png

     

    rbjames_0-1719320458555.png

     

    I've tried having a static value in place of varSelLesson but no luck.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 339 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 289

#3
Mohsin Ali Profile Picture

Mohsin Ali 228

Last 30 days Overall leaderboard