"Specified cast is not valid" error after changing the type of the "Total" field from "Number" to "Amount of Money" in the invoice project

Symptoms

The error

The type of the field Invoice Layout\Total is incompatible with a Check Sum
  rule. System.InvalidCastException: Specified cast is not valid

appears after changing the type of the "Total" field from "Number" to "Amount of Money" in the invoice project.

Cause

This issue appears because of the incorrect conversion in the Invoice Layout\Total script rule.

Resolution

The solution for this behavior is the modification of the Invoice Layout\Total script rule. By default, the type of the total variable in this script is double:

double total = (double)( Context.Field("Total").Value );

This is causing the conversion error because the type of the "Total" field is now "Amount of Money". In order to fix it, please change the type of the total variable from double to decimal:

decimal total = (decimal)( Context.Field("Total").Value );

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.