Hello CU12030941-0,
You've done a thorough job troubleshooting, and you're very close to the solution! The issue you're facing is a common one when working with polymorphic lookup fields in Dataverse (like the "Customer" field on the Case entity) using Canvas Apps.
Here's a breakdown of the problem and the correct approach:
Understanding the Problem:
- Polymorphic Lookup:
- The "Customer" field is polymorphic, meaning it can reference either an Account or a Contact.
- This requires you to specify not only the GUID of the record but also the entity type.
- OData Binding:
- While @odata.bind is the correct approach, you need to use the correct format for polymorphic lookups.
The Solution:
The key is to include the entity set name (either "accounts" or "contacts") in the @odata.bind string.
Here's the corrected Patch() statement:
Code snippet (Example)
Patch(
Caso, // or "Casi", the data source
Defaults(Caso),
{
'Titolo caso': TitleTextInput.Text,
'Priorità': PriorityComboBox.Selected.Value,
// ... other fields ...
'customerid_account@odata.bind': "/accounts(" & ComboBox1.Selected.accountid & ")"
}
);
Explanation:
- 'customerid_account@odata.bind': "/accounts(" & ComboBox1.Selected.accountid & ")":
- This correctly specifies the entity set name ("accounts") followed by the GUID of the selected account.
Key Points:
- Entity Set Name:
- Always include the entity set name ("accounts" or "contacts") in the @odata.bind string for polymorphic lookups.
- GUID Format:
- Ensure the GUID is in the correct format (e.g., "d253fa15-e7f5-ef11-be21-003248a356b7").
- Combo Box Selection:
- Verify that the Combo Box is correctly returning the selected account's GUID.
If you want to support Contacts as well:
If you need to support selecting both Accounts and Contacts in your Combo Box, you'll need to:
- Combine Data Sources:
- Combine the Accounts and Contacts tables into a single collection or view that the Combo Box can use.
- This can be done using the choices function.
- Add Entity Type:
- Add a field to the collection that indicates the entity type (e.g., "Account" or "Contact").
- Conditional Patch:
- Use an If() statement in your Patch() function to conditionally set the @odata.bind property based on the selected entity type.
Example of using the choices function.
Code snippet (Example)
ClearCollect(
CombinedCustomers,
ForAll(
Accounts,
{
CustomerId: accountid,
CustomerName: accountname,
CustomerType: "accounts"
}
),
ForAll(
Contacts,
{
CustomerId: contactid,
CustomerName: fullname,
CustomerType: "contacts"
}
)
);
Then your patch statement would look like this.
Code snippet (Example)
Patch(
Caso, // or "Casi", the data source
Defaults(Caso),
{
'Titolo caso': TitleTextInput.Text,
'Priorità': PriorityComboBox.Selected.Value,
// ... other fields ...
'customerid_account@odata.bind': If(ComboBox1.Selected.CustomerType = "accounts","/accounts(" & ComboBox1.Selected.CustomerId & ")", Blank()),
'customerid_contact@odata.bind': If(ComboBox1.Selected.CustomerType = "contacts","/contacts(" & ComboBox1.Selected.CustomerId & ")", Blank())
}
);
By making these adjustments, you should be able to successfully create Cases with the correct Customer reference.
If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
If you have further questions, please feel free to contact me.
My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
Best Regards,
Daivat Vartak