
Hi,
I believe I am close however the function call is failing on the datatypes of the parameter values in the hashtable as follows:
Invoke-CrmAction : Exception calling "Execute" with "1" argument(s): "Input field type 'Int32' does not match expected type 'OptionSetValue' for field
'HighestOffenceLevel'"
At C:\Transfer\ServiceDateBasedRates\ServiceDateRateTest.ps1:194 char:15
+ ... $Result = Invoke-CrmAction 'lss_ACTION_TariffItemRateCalcRateOnly' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CrmAction
I am trying to pass in a value of 0 to the parameter. I am not embedding the value in quotes so it is interpreted as a number and there is no decimal point.
The actual action function call is:
$Result = Invoke-CrmAction 'lss_ACTION_TariffItemRateCalcRateOnly' -Parameters @{AdministrativeRate=1;AltServiceProviderType='';ContractIsCriminalStandard=0;DateContractIssued=1/1/2019;HighestOffenceLevel=0;IndictableRate=3;LawyerCallDate='';LawyerExperienceAdjustmentAmount=1.1;LinkedContractAdjustmentAmount=1;MajorRate=4;ServiceDate=2/2/2019;SummaryRate=2;UnitOfMeasure=863600000;UnitRate=5}
Any guidance on how to format the different CRM parameter data types in the action call would be help as I suspect that I will run into issues with the Money columns as well.
Thank you.
Mat
I have worked this out myself with a whole lot of trial and error and discussion with a CSharp developer who was working on a console app version of this at the same time. the solution was to pass in conversion functions as part of the hashtable. As a result each type of action parameter requires a different conversion function resulting in my case with the following call to the action:
$Result = Invoke-CrmAction 'lss_ACTION_TariffItemRateCalcRateOnly' -Parameters @{AdministrativeRate=new-object Microsoft.Xrm.Sdk.Money($AdministrativeRate);AltServiceProviderType=[convert]::ToInt32($AltServiceProviderType);ContractIsCriminalStandard=[System.Convert]::ToBoolean($ContractIsCriminalStandard);DateContractIssued=[datetime]::parseexact("$DateContractIssued", "dd/MM/yyyy", $null);IndictableRate=new-object Microsoft.Xrm.Sdk.Money($IndictableRate);LawyerExperienceAdjustmentAmount=[convert]::ToDouble($LawyerExperienceAdjustmentAmount);LinkedContractAdjustmentAmount=[convert]::ToDouble($LinkedContractAdjustmentAmount);MajorRate=new-object Microsoft.Xrm.Sdk.Money($MajorRate);ServiceDate=[datetime]::parseexact("$ServiceDate", "dd/MM/yyyy", $null);SummaryRate=new-object Microsoft.Xrm.Sdk.Money($SummaryRate);UnitOfMeasure=[convert]::ToInt32($UnitOfMeasure);UnitRate=new-object Microsoft.Xrm.Sdk.Money($UnitRate)}
The key being the Microsoft.Xrm.Sdk conversions as these handle CRM specific data types such as Money and Pick List items.
Hope this helps others in the future.