web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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

I have the same question (0)
  • Suggested answer
    TheRealPobblebonk Profile Picture
    15 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 128 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 113

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans