Hello!
I have multiple multi-choice Dataverse columns.
I want to assign each choice a number. For example:
'Sales Channels' - Multi-choice column in a form
Amazon = 125
Shopify = 150
'Payment Processors' - Multi-choice column in a form
PayPal = 100
Stripe = 125
'Banks' - Multi-choice column in a form
Wells Fargo = 100
Chase = 75
Let's say Amazon, Shopify, WellsFargo and only PayPal are selected, I want them to be totaled up and saved to an Invoice column after I hit the save button.
So the Invoice column would read Invoice: $375
Here is my OnStart code I am using so far:
ClearCollect(SalesChannelsToInt,
{Choice: "Amazon", Value: 100, Id: GUID()},
{Choice: "eBay", Value: 125, Id: GUID()},
{Choice: "Shopify", Value: 150, Id: GUID()}
);
ClearCollect(PaymentProcessorsToInt,
{Choice: "PayPal", Value: 80, Id: GUID()},
{Choice: "Stripe", Value: 100, Id: GUID()},
{Choice: "Square", Value: 75, Id: GUID()}
);
Here is my Onselect Code for my Save button:
SubmitForm(Form1);
// Clear the collection "SelectedSalesChannelsInt" to prepare for fresh data.
Clear(SelectedSalesChannelsInt);
// For each item in the last submitted form's 'Sales Channels' field...
ForAll(Form1.LastSubmit.'Sales Channels'.Value,
// ... look up the associated value in the SalesChannelsToInt collection and add it to the SelectedSalesChannelsInt collection.
Collect(SelectedSalesChannelsInt, LookUp(SalesChannelsToInt, Choice = Value).Value)
);
// Clear the collection "SelectedPaymentProcessorsInt" to prepare for fresh data.
Clear(SelectedPaymentProcessorsInt);
// For each item in the last submitted form's 'Payment Processors' field...
ForAll(Form1.LastSubmit.'Payment Processors'.Value,
// ... look up the associated value in the PaymentProcessorsToInt collection and add it to the SelectedPaymentProcessorsInt collection.
Collect(SelectedPaymentProcessorsInt, LookUp(PaymentProcessorsToInt, Choice = Value).Value)
);
// Clear the collection "SelectedBanksInt" to prepare for fresh data.
Clear(SelectedBanksInt);
// For each item in the last submitted form's 'Banks' field...
ForAll(Form1.LastSubmit.Banks.Value,
// ... look up the associated value in the BanksToInt collection and add it to the SelectedBanksInt collection.
Collect(SelectedBanksInt, LookUp(BanksToInt, Choice = Value).Value)
);
// Sum up all the values
Set(TotalInvoiceValue, Sum(SelectedSalesChannelsInt, Value) + Sum(SelectedPaymentProcessorsInt, Value) + Sum(SelectedBanksInt, Value));
// Patch the result to the Invoice column
Patch(Companies, Form1.LastSubmit, { Invoice: TotalInvoiceValue })
It's currently patching a "0" to my invoice column and I have the yellow! error on the OnSelect property of my Save button.
Issue
Incompatible types for comparison. These types can't be compared. Text, Number.
We can't evaluate your formula because the values being compared in the formula aren't the same type.
Looks like these 3 chunks of the code are the culprit:
Collect(SelectedPaymentProcessorsInt, LookUp(PaymentProcessorsToInt, Choice = Value).Value)
Collect(SelectedSalesChannelsInt, LookUp(SalesChannelsToInt, Choice = Value).Value)
Collect(SelectedBanksInt, LookUp(BanksToInt, Choice = Value).Value)
Any suggestions would be lovely!
Thanks