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 / When emailing a html t...
Power Apps
Answered

When emailing a html table it is picking up the wrong ID of the record

(0) ShareShare
ReportReport
Posted on by 380

@WarrenBelz I have a htmltext object in my app which contains a html table which basically represents a report for the user. It is only accessible from a Gallery I have created and I set a number of variables on the OnSelect button they press to receive an emailed report.

 

In the html table I refer to all fields from the variables I have set for example varRecord.tripdate or varRecord.tripid and varContact.homemobile etc and they are all set to Gallery5.Selected (my main Gallery from where they can email the report to themselves)

 

I have this code to email the report:

Office365Outlook.SendEmailV2(
 varUserMail,
 "Printable report for Field Trip " & varRecord.tripid & " - click on the TripID to open the app",
 TRIPREPORT.HtmlText,
 {IsHtml: true}
);

varUserMail is the email of the logged-on user and tripid is the unique ID of the trip

 

The email is received and the html table can be seen within the body of the email however the tripid is the one before the one just selected. So if I choose tripid 1234 and the one I previously looked at was 998 it will show me 998. If I then go and choose 1235 it will show me 1234!!   So it's one step behind every time

 

If I go to the htmltext object in edit mode it will show the last tripid selected and it is correct so if I chose 1234 it shows 1234

 

Here is the code on the OnSelect property of the button to email the report:

Set(
 varContact,
 Gallery7_1.Selected
);
Set(
 varRecord,
 Gallery5.Selected
);
ClearCollect(
 colOfficers,
 ForAll(
 Sequence(CountRows(Gallery4_2.AllItems)),
 Patch(
 Last(
 FirstN(
 Gallery4_2.AllItems,
 Value
 )
 ),
 {RowNumber: Value}
 )
 )
);
ClearCollect(
 colDetails,
 ForAll(
 Sequence(CountRows(Gallery6.AllItems)),
 Patch(
 Last(
 FirstN(
 Gallery6.AllItems,
 Value
 )
 ),
 {RowNumber: Value}
 )
 )
);
Office365Outlook.SendEmailV2(
 varUserMail,
 "Printable report for Field Trip " & varRecord.tripid & " - click on the TripID to open the app",
 TRIPREPORT.HtmlText,
 {IsHtml: true}
);

it's like varRecord is retaining it's contents until AFTER the report is emailed....so if I choose tripid 1234 twice, the second time it works!!

Categories:
  • WarrenBelz Profile Picture
    156,738 Most Valuable Professional on at

    Hi @bobgodin ,

    This will be about when/where you are setting the Variable - so for a start, how and when do you set varRecord ?

  • bobgodin Profile Picture
    380 on at

    Hi @WarrenBelz in my code I posted (on the OnSelect property of a button in my Gallery) you'll see 5 lines from the top: 

    Set(
     varRecord,
     Gallery5.Selected
    );

    then I do other stuff before the SendEmail at the bottom. I ran extensive tests yesterday:

    1. I commented out the sendemail code so I stopped just before executing this - I check the variable and sure enough it was correct - it had set varRecord to Gallery5.Selected

    2. I changed the code so that instead of the sendemail statement I did a Navigate to TRIPREPORT.HtmlText - it displayed the correct information.

    3. I put a button on the HtmlText object to execute the sendemail statement and it worked perfectly

     

    it would seem there is a timing issue when I put it all together.....

  • WarrenBelz Profile Picture
    156,738 Most Valuable Professional on at

    Hi @bobgodin ,

    Have you tried OnSelect of Gallery5

    Set(
     varRecord,
     ThisItem
    );

    That should definitely set it and update anything reliant on it.

     

  • bobgodin Profile Picture
    380 on at

    Hi @WarrenBelz tried that - same result.

    When opening the app in Edit mode the 1st time and clicking the button for the email - the email is received but there is no data in the table - meaning it hasn't picked up varRecord data at all.

    When I click the button a 2nd time I get the tripid I chose the 1st time not eh one I selected this time.

     

    It seems to me to be a bug in the sendemailv2 function that is somehow caching the contents of the htmltext object - is this possible? Can I reset the htmltext object before I set varRecord?

  • WarrenBelz Profile Picture
    156,738 Most Valuable Professional on at

    Hi @bobgodin ,

    Have you tried putting the HTML Text in a HTML Text box and then sending that as the Body of the email ?

  • bobgodin Profile Picture
    380 on at

    Hi @WarrenBelz that's exactly what I'm doing Warren

  • WarrenBelz Profile Picture
    156,738 Most Valuable Professional on at

    Hi @bobgodin ,

    This is not making a lot of sense - after you set varRecord on the OnSelect of the Gallery, what do you immediately see in the HTML Box ?

  • bobgodin Profile Picture
    380 on at

    Hi @WarrenBelz if I just navigate to the htmltext object I see the trip report with the correct data from varRecord - if I enable the sendemail function I wait 3 seconds and then open the email which displays the last tripid I chose NOT the current one - I am going to break it down on a 2nd htmltext page with just 2 fields in a table and see if that works.....

  • bobgodin Profile Picture
    380 on at

    Hi @WarrenBelz I ran a few tests where I used a HtmlText object with very limited data fields - I used tripid and date and it worked fine. The problem is in one section of my Html table I am doing a lot of lookups on people's names against Office365Users/Managers where I am saying only show this information if you are the user or the user's supervisor/manager/manager's manager/managers/managers/manager etc and I do this multiple times so there is a lot of processing that needs to occur

     

    I think Microsoft have a timeout for the sendemail function to complete and if it looks like its not going to be able to process everything it just uses the last (cached) varRecord.

     

    I have proved this my excluding that chunk of data and just presenting the rest of the html table and it works fine - I  click the button and 3 seconds later the email arrives populated correctly.

     

    So what I have to do now is take the LookUp statements out of the htmltext box and put them into the OnStart of the app so I set those "permissions" up early in the piece then I can refer to a variable in my htmltext object without all the processing going on. Did I explain that well enough? lol

  • WarrenBelz Profile Picture
    156,738 Most Valuable Professional on at

    Hi @bobgodin ,

    I must admit I have never encountered this bug, but I would have thought if you resolved all the Variables before you triggered the email (the HTML has time to "settle down", it should be fine. I also noticed another Variable - you can also set on Gallery7_1 OnSelect

    Set(varContact, ThisItem)

    also how do colOfficers and colDetails figure in the HTML code (you can cut down a bit of code here - I am assuming you are using RowNo in the HTML somewhere)

    ClearCollect(
     colOfficers,
     ForAll(
     Sequence(CountRows(Gallery4_2.AllItems)),
     Patch(
     Index(
     Gallery4_2.AllItems,
     Value
     ),
     {RowNumber: Value}
     )
     )
    );
    ClearCollect(
     colDetails,
     ForAll(
     Sequence(CountRows(Gallery6.AllItems)),
     Patch(
     Index(
     Gallery6.AllItems,
     Value
     ),
     {RowNumber: Value}
     )
     )
    );

     

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 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 320

#3
Mohsin Ali Profile Picture

Mohsin Ali 246

Last 30 days Overall leaderboard