This part adds a new prospect to Dynamics 365 Sales from a canvas app. The form writes to the standard Dataverse Lead table and reports success only after the create operation succeeds.
1. Build the capture form
Add inputs for Topic, First Name, Last Name, Company, Email, and Business Phone. In a production app, use an Edit form bound to Leads where possible; it respects Dataverse column types and makes required-field handling easier. The following Patch example illustrates a lightweight custom form.
2. Validate required values
If(
IsBlank(Trim(txtTopic.Text)) ||
IsBlank(Trim(txtLastName.Text)) ||
IsBlank(Trim(txtCompany.Text)),
Notify(
"Enter a topic, last name, and company.",
NotificationType.Warning
),
/* continue with the Patch operation */
)
3. Create the Dataverse record
IfError(
Set(
varCreatedLead,
Patch(
Leads,
Defaults(Leads),
{
subject: Trim(txtTopic.Text),
lastname: Trim(txtLastName.Text),
companyname: Trim(txtCompany.Text),
firstname: Trim(txtFirstName.Text),
emailaddress1: Lower(Trim(txtEmail.Text)),
telephone1: Trim(txtPhone.Text)
}
)
),
Notify(
"Lead could not be created: " & FirstError.Message,
NotificationType.Error
),
Notify("Lead created successfully.", NotificationType.Success);
Refresh(Leads);
Set(varSelectedLead, varCreatedLead);
Navigate(scrLeadDetails, ScreenTransition.Fade)
)
Column names shown are common Lead logical names; use IntelliSense and verify required columns, business rules, and custom plug-in validations in your Dataverse environment. Do not add status or owner values unless your process explicitly requires them.
4. Verify the save
- Confirm the returned record has a Lead ID.
- Open the same lead in Dynamics 365 Sales and compare the values.
- Test duplicate detection and server-side business rules.
- Test with a user who has create but not append/assign privileges to identify missing permissions.
For a full form experience, use SubmitForm and handle Form.OnSuccess and Form.OnFailure. This prevents navigating away before Dataverse confirms the save.
