Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Issues running Invoke-CrmAction (Microsoft.Xrm.Data.Powershell) from powershell

(0) ShareShare
ReportReport
Posted on by 15

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

  • Suggested answer
    TheRealPobblebonk Profile Picture
    15 on at
    RE: Issues running Invoke-CrmAction (Microsoft.Xrm.Data.Powershell) from powershell

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

#3
Sahra Profile Picture

Sahra 43

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans