Submitting data via a Canvas App
This post describes how to submit data from a Canvas App’s edit form into Dataverse. Specifically, it provides an example of how to use the SubmitForm and Patch functions to achieve this. It also describes how to perform validation of the data on the form before submission.
Within the Canvas Apps studio, an edit form is created with fields from the Enquirer entity placed on the form.
Form Data Validation
When the Submit button is pressed, the following script (screenshot 2) which resides within the button’s OnSelect property, is executed. (DataCardValue31 = the Facility drop down box.)
Since the Facility drop down box isn’t populated, the following error is generated.
A similar message would be produced if either ‘Enquirer First Name’ or ‘Enquirer Last Name’ weren’t populated (since they are mandatory fields).
Form Data Submission
Referring to the script in Screenshot 2, once the line SubmitForm(enquirer) is successfully executed, the form’s OnSuccess property (Screenshot 4) is then executed. The script for this is listed below (Screenshots 5, 6, 7 & 8).
The first part of the script (Screenshot 5) stores a reference to the Enquirer record that was submitted in the SubmitForm call.
The second part of the script (Screenshot 6) adds the Enquirer Type value to this record in Dataverse. This type of call is usually performed for columns (fields) that aren’t displayed on the form but still need to be stored in Dataverse.
The third part of the script (Screenshot 7) creates a new Case record in Dataverse. (The Customer lookup and Case Type option set are both populated.)
The fourth and final part of the script (Screenshot 8) inspects the global variable ReferrerExits (this is displayed as a checkbox on the form) to determine whether to load the Case Screen on not.
Exposing the Canvas App
The app could now be made available. For example, in a Dynamics 365 App