Blog

Bug - What to do when setting a variable to Form.LastSubmit doesn't work

A recent update to Power Apps can cause formulas that set Form.LastSubmit to fail. This post summarises this bug and describes how to fix it.

A recent update to Power Apps may cause formula that sets variables to Form.LastSubmit to not work, especially for new apps.

What's the purpose of Form.LastSubmit?

The LastSubmit property enables us to retrieve the record that was last edited or added via a form control. This is crucial for obtaining server-generated values like the ID number of a new record.

What happens when setting a variable to Form.LastSubmit? 

A common practice is to store the LastSubmit value in a variable in the OnSuccess property of a form like so.

Set(varLastRecord,
Self.LastSubmit
)

As a result of this bug, it isn't possible to access any of the fields in the variable after calling Set. For example, if we enter 'varLastSubmit.' into the text property of a label, the Intellisense in the designer does not show any of the fields.

If we examine the variables pane in the designer, notice how the left hand panel correctly shows the JSON of the LastSubmit record, whereas the body of the variable is blank. 


Is it possible to set a variable to Form.LastSubmit? 

To work around this bug, we might attempt to set the variable to the ID property of LastSubmit.

Set(varLastRecordID,
Self.LastSubmit.ID
)


When we do this, the call to Set fails and varLastRecordID is completely inaccessible and not visible in the variables pane.

Does using a context variable make any difference? 

Using a context variable rather than a global variable makes no difference. The context variable also appears blank, as shown beneath.


How to resolve this bug 

The cause of this bug is the new analysis engine, which is enabled by default for new apps.

To solve this problem, turn off the 'New analysis engine' option in the Updates> New section of the app settings. 


Once we reload the designer, setting a variable to LastSubmit will work as expected. In the screenshot below, note how the LastSubmit details now appear in the body of the variables pane.


Conclusion

Currently, the new analysis engine prevents accessing the LastSubmit value through a variable. Turning off this setting fixes the issue. Hopefully, Microsoft will address this bug soon.
  •   Categories: 
  • bug