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 / LastSubmit and With?
Power Apps
Unanswered

LastSubmit and With?

(0) ShareShare
ReportReport
Posted on by 219

I have the form called frmTicketDataEntry and the onsuccess property is this...

With({
 _frm: FrmTicketRequest.LastSubmit
},
Switch(
 _frm.StatusId,
 1,
 Office365Outlook.SendEmailV2(
 "Blah@acme.com",
 _frm.'Seats Requested' & " Pending" & _frm.TicketStatusId,
 "Something"
 ),
 2,
 Office365Outlook.SendEmailV2(
 "Blah@acme.com",
 _frm.'Seats Requested' & " Approved" & _frm.TicketStatusId,
 "Something"
 ),
 3,
 Office365Outlook.SendEmailV2(
 "Blah@acme.com",
 _frm.'Seats Requested' & " Waitlisted" & _frm.TicketStatusId,
 "Something"
 ),
 4,
 Office365Outlook.SendEmailV2(
 "Blah@acme.com",
 _frm.'Seats Requested' & " Cancelled" & _frm.TicketStatusId,
 "Something"
 ),
 5,
 Office365Outlook.SendEmailV2(
 "Blah@acme.com",
 _frm.'Seats Requested' & " Denied" & _frm.TicketStatusId,
 "Something"
 ),
 /* what to do about these? */
 Office365Outlook.SendEmailV2(
 "Blah@acme.com",
 _frm.TicketStatusId & " We have no custom email for this" & _frm.TicketStatusId,
 "Something"
 )

));
ResetForm(FrmTicketRequest);
Navigate(EventDataEntry);
Notify(
 "Ticket Request Saved",
 NotificationType.Success,
 5
);


Power apps doesn't like this... name isn't valid. So the onSelect for the form is simply SubmitForm(FrmTicketRequest)
Then this onSuccess property I'm trying to set is definitely on the same form. 
What am I doing wrong?

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc1966 

    Which "name isn't valid" are you seeing the error on?

     

    Also, consider changing your formula to a simpler and more maintainable formula.

    With(Self.LastSubmit,
     Office365Outlook.SendEmailV2(
     "Blah@acme.com",
     'Seats Requested' & 
     Switch(StatusId, 
     1, " Pending",
     2, " Approved",
     3, " Waitlisted",
     4, " Cancelled",
     5, " Denied",
     " We have no custom email for this"
     ) & TicketStatusId,
     "Something"
     )
    );
     
    ResetForm(FrmTicketRequest);
    Navigate(EventDataEntry);
    Notify("Ticket Request Saved", NotificationType.Success,5);

     

    The concerns I would have would be over the data type for the columns 'Seats Requested' and TicketStatusId.  Are they all simple columns (i.e. Text)?

     

    I hope this is helpful for you.

  • sasrsc1966 Profile Picture
    219 on at

    Yes. the ticketStatusID and 'seats requested' are both simple numeric vars.
    But I am going to have to look up other info from other tables before sending the email...
    My emails although not reflective quite now, will vary greatly in the content. This is just step 1 of the long list of baby steps. 
    For example - self.LastSubmit.EventId .... I'd need to lookup(Events, ID=self.LastSubmit.EventId (and the same with venues...needing the Venue information.
    So I'm trying to get the grasp on using With... and as I understand it, you have to nest them if you want to use a value from the temporary record.. so in this example (which Power App doesn't like)... I've got the red underline
    on line too "invocation of unknown or unsupported function". But hear me out... 
    On line 1 I create a temporary rec called _frm but I can't reference that unless I nest another with so line 2 should work. But as I said Power Apps has the red pen out, so I'm failing again. I made a typo on the previous example as my switch is based on the TicketStatusId

    I think your suggestion makes sense for a more consistent email, but sorry I didn't explain myself better.


    With({_frm: Self.LastSubmit},
     With({_e: Lookup(Events,ID=_frm.EventId)},
     With({_v: Lookup(Venues,ID=_e.VenueId)},
     
     Switch(
     _frm.TicketStatusId
     1,
     Office365Outlook.SendEmailV2(
     "Blah@acme.com",
     _frm.'Seats Requested' & " Pending" & _frm.TicketStatusId,
     "Something"
     ),
     2,
     Office365Outlook.SendEmailV2(
     "Blah@acme.com",
     _frm.'Seats Requested' & " Approved" & _frm.TicketStatusId,
     "Something"
     ),
     3,
     Office365Outlook.SendEmailV2(
     "Blah@acme.com",
     _frm.'Seats Requested' & " Waitlisted" & _frm.TicketStatusId,
     "Something"
     ),
     4,
     Office365Outlook.SendEmailV2(
     "Blah@acme.com",
     _frm.'Seats Requested' & " Cancelled" & _frm.TicketStatusId,
     "Something"
     ),
     5,
     Office365Outlook.SendEmailV2(
     "Blah@acme.com",
     _frm.'Seats Requested' & " Denied" & _frm.TicketStatusId,
     "Something"
     ),
     /* what to do about these? */
     Office365Outlook.SendEmailV2(
     "Blah@acme.com",
     _frm.TicketStatusId & " We have no custom email for this" & _frm.TicketStatusId,
     "Something"
     )
     ) // end of switch
     ) // end of second inner with
     ) // end of first inner with
    ); // end of outer with

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc1966 

    Well, you have a syntax error in your formula which is why you are seeing the error that you are.  LookUp has a capital U in it.

     

    As for the With statement, yes, if you are referring to a variable that is defined at one level, you need to have another nested with.

     

    Here are two differences (and why you would nest and nest and nest again):

    With({_frm: Self.LastSubmit,
     _e: LookUp(Events, ID=Self.LastSubmit.EventId),
     _v: LookUp(Venues, ID=LookUp(Events, ID=Self.LastSubmit.EventId).VenueId)
     },
     ...variables _frm, _e and _v all available here
     ...etc..

    You can see with the above that there is duplication of formula and not easy to maintain.  Plus, in that case, you will be doing redundant data operations.

    So, the concept of the With in the above is that you are creating three scoped variables - _frm, _e and _v.  And it is expected then that you will use them somewhere in the With statement that you are defining.

     

    SO...to simplify (and reduce redundancy), you would nest these as they "build" on each other:

    With({_frm: Self.LastSubmit},
     With({_e: LookUp(Events, ID=_frm.EventId)},
     With({_v: LookUp(Venues, ID=_e.VenueId)},
     ...variables _frm, _e and _v all available here
     ...etc..

    So, in this formula, it is more efficient and easier to maintain.

     

    Now, in looking at your other post, you seemed to accept the solution for send to flow at this point rather than to using the SendEmailV2 action, so the formula would need to change for that.

    Based on what I was saying in that other post, I would then use the output of the component for formatting the email in the above formula.

    And definitely, change your redundancy in the switch statement to what I previously sent.  You really only want to Switch on that which is changing (the Subject line), not on the entire formula (i.e. the SendEmailV2).

  • sasrsc1966 Profile Picture
    219 on at

    Yes, all good points.
    I think this would be a great scenario for Power Automate because of the variable situation (it will be used in multiple places and there are numerous values that are conditional).
    But I was hoping to master this and then most likely convert it to a Power Automate routine. But I'm still not comfortable with "with" and grasping it... Other than the Lookup and LookUp typo I thought it should have worked but it doesn't...so I simplified this (went back to basics)... I created a text label and this is the text property...so again it's still not working. My nested withs aren't the issue......

    By the way - you'd make a good teacher. You have great patience (and it's probably wearing thin with my questions)


    Region Capture.jpg

    With({_frm: FrmTicketRequest.LastSubmit},
     With({_e: LookUp(Events,ID=_frm.EventId)}, // get Event Info
     With({_v: LookUp(Venues,ID=_e.VenueId)}, // get Venue Info
     // now do a different email based on the status
     Switch(
     _frm.TicketStatusId
     1,
     _e.Title & _v.Title,
     2,
     "Blah",
     "Something Else" 
     ) // end of switch
     ) // end of second inner with
     ) // end of first inner with
    )// end of outer with

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc1966 

    Ah no, I do teach this stuff, so, patience is a virtue!! 🙂  I love to watch concepts start to solidify in peoples minds as the pieces all start to come together.  There is a real thrill to get past the "how do you do this" and move on to the real logic, function and design of the app.  Your apps will then explode with features and functionality!

     

    So in your switch case, you are trying to compare text to numbers.  

    Try changing to the following:

    With({_frm: FrmTicketRequest.LastSubmit},
     With({_e: LookUp(Events,ID=_frm.EventId)}, // get Event Info
     With({_v: LookUp(Venues,ID=_e.VenueId)}, // get Venue Info
     // now do a different email based on the status
     Switch(
     Value(_frm.TicketStatusId)
     1, _e.Title & _v.Title,
     2, "Blah",
     "Something Else" 
     ) // end of switch
     ) // end of second inner with
     ) // end of first inner with
    )// end of outer with

    If that column is a simple text column, then it needs to be converted.  I was originally under the impression that it was numeric.

  • sasrsc1966 Profile Picture
    219 on at

    This indeed is a long journey but like you - I get a "kick" out of seeing the light bulb go off.
    I modified my Text label and got it to work...so some things I learned along the way...

    1) my _frm.TicketStatusId is definitely numweric. In the end wrapping it in Value wasn't necessary.
    2) the issue it appear was that the onSuccess was doing a ResetForm(FrmTicketRequest); which blanks out the form once submitted and onsuccess. So the value for frmTicketRequest.LastSubmit.TicketStatusId was blank.
    3) Once I commented that resetform it worked for the text label.
    4) What's strange is why does LastSubmit get blanked out. I thought ResetForm would blank the current form values but not the LastSubmit. 
    5) Originally in my example the resetform came AFTER the with/switch statement but I'm going to not worry about that because I think the meat of my issue was trying to do so much within the switch statement. In our label case it's an output of a simple "string" value...

    So for those that are listening - this works as a label.text property...

    With({_frm: FrmTicketRequest.LastSubmit},
     With({_e: LookUp(Events,ID=_frm.EventId)}, // get Event Info
     With({_v: LookUp(Venues,ID=_e.VenueId)}, // get Venue Info
     // now do a different email based on the status
     Switch(
     _frm.TicketStatusId,
     1,
     _e.Title & _v.Title & " Pending",
     2,
     _e.Title & _v.Title & " Confirmed",
     "Something Else='" & _frm.TicketStatusId &"'"
     ) /* end of switch */
     ) /* end of second inner with */
     ) /* end of first inner with */
    ) /* end of outer with */

    But now I know this and my grasp of "with" is getting better I'm going to move this to Power Automate to handle the various versions of the email.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc1966 

    Ah ha...you had some mystery pieces of the puzzle that I was not clear on.  I realized you were testing some things out, but not seeing that you were doing them in tandem with one another.

    SO...Yes, ResetForm will reset the LastSubmit property!  It's actually important that it does that.  

    In general, when dealing with a form:

    1) Never reference the datacardvalue controls on the form outside of the form (unless it is transient).  Datacardvalue controls can and will change from what you expect them to be during the SubmitForm stage.

    2) Always rely on the LastSubmit record of the form - however...if you expect to reference this outside of the OnSuccess or anticipate doing a ResetForm anywhere, then capture the record in the OnSuccess in a snapshot variable:  Set(glbCurrentRecord, Self.LastSubmit)  then you will have this record from that point on until another form is submitted.

     

    So yes, the formula should remain quite simple and always be so.  The trick is to capture things when and where you need them and if you need to, then to reference everything.  

     

    A little trick about the Forms - consider always working with a global variable for the Item of the form (ex. glbCurrentRecord).  Keep the form in Edit mode and never issue a NewForm function.  If you want a new record, set the global variable to the defaults of the datasource - i.e. Set(glbCurrentRecord, Defaults(yourDataSource)) Once you do this, your form will be essentially in New mode and you will create a new record when you SubmitForm.  In the OnSuccess set that variable to Self.LastSubmit.  The form will now be showing that current record and be editing it.  If you submit again, it will be updating that correct record.

    In other words, the values in the variable govern what the form is doing.  This will give you much more control and clarity with the form.

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard