0
votes

I am trying to add a new field through the customization browser to the Purchase Orders screen (PO301000). I created the field through the New Field button and edited the Data Access slightly to provide a default parameter for the field. Here is the code in the Data Access:

[PXDBDecimal]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName="Weight Total")]

This field will be used to calculate the total weight of the purchase order and I would like it to be stored in the database. I get this error when publishing:

An error while publishing the database item POOrder
 with the message:
Nullable object must have a value.

I have tried changing the PXDBDecimal to a PXDBQuantity. This has to be done through the customization browser and not the database itself because this project will be going on a SaaS hosted site where I do not have access to the database. I have also tried creating the field through the DAC only and I receive this error when trying to open the page:

    Invalid column name 'UsrWeightTotal'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'UsrWeightTotal'.
1
you need the table entry in your project. Do you have one if you look at the project xml? also for PXDefault you are saying that all records (including previous orders) require a value. It would be good to allow nulls for previous records by changing the persisting check on PXDefault for that field - Brendan
I have added PersistingCheck=PXPersistingCheck.Nothing and the table is POOrder in the Project XML, I'm still getting the same issue. - Dane
Where in the publish process to you get the error? During validation? - Brendan
No it is right after that point when databases are being updated. - Dane
Is the Usr field setup to be nullable in SQL? Otherwise it would need a sql default value of zero - Brendan

1 Answers

1
votes

When reviewing the project xml for the POOrder table entry in the customization I found there were some extra/missing attributes required for a column type of decimal.

There was a MaxLength property and no DecimalLength property. I compared it to adding a new field of type decimal and looked at the project xml to come up with the following:

<Table TableName="POOrder"> 
<Column TableName="POOrder" ColumnName="UsrWeightTotal" ColumnType="decimal" AllowNull="True" DecimalPrecision="6" DecimalLength="19" IsNewColumn="True" IsUnicode="True" /> 
</Table>

I bet the error was complaining about the missing DecimalLength value (as a result was null but required for the publish process).