Form1.LastSubmit.ID is usually the right approach, but the issue is timing. SubmitForm(Form1) is asynchronous, so your UpdateContext({ varNewRecordID: Form1.LastSubmit.ID }) can execute before the record is actually committed to SharePoint. That means Form1.LastSubmit.ID is blank or invalid when the flow runs, which is why the flow never triggers.
You should move the upload logic into the form’s OnSuccess property, because OnSuccess only fires after the SharePoint item is successfully created and the ID exists. Try this structure instead // Submit Button OnSelect SubmitForm(Form1). Then in the form's OnSuccess:
Set(varNewRecordID, Form1.LastSubmit.ID);
// Upload Datasheets
ForAll(
Datasheets.Attachments,
'UploadAttachmentstoLibrary'.Run(
Text(varNewRecordID),
"Datasheet",
{
file: {
name: ThisRecord.Name,
contentBytes: ThisRecord.Value
}
}
)
);
A few important notes: Set() is generally safer here than UpdateContext() because it creates a global variable and avoids some screen-context timing quirks. Form1.LastSubmit.ID is only guaranteed to exist inside OnSuccess. If the flow parameter expects a number, remove Text() and pass varNewRecordID directly. Another thing to watch for, If Datasheets is an attachment control from an Edit Form, ThisRecord.Value can sometimes be problematic depending on the connector version. Some people instead use contentBytes: Value inside the ForAll.
You do not need to do a Get Items in the flow just to find the ID if you already have it in Power Apps. Passing the ID directly is cleaner and more efficient.
🏷️ Please tag me @Kushal_M, if you still have any queries related to the solution or issue persists.
❤️ Please consider giving it a Like, If the approach was useful in other ways.
✅ Please click Accept as solution if my post helped you solve your issue and help others who will face the similar issue in future.