'API Call from Custom field not showing the same data type

Tried to do an API Call from a custom field that I published in one of our instance. The result value of the corresponding field didn't match the data type in our Data class. My field data type is Int but through the API, I got String instead. Also the field control element for this field is ComboBox

What I expect for the Kundengruppe value:

{
        "id": "4b2758c6-8d86-4357-871e-70621d09719d",
        "rowNumber": 3,
        "note": null,
        "Kundengruppe": {
            "value": "1" //
        },
        "UUID": {},
        "custom": {}
}

What I get:

{
        "id": "4b2758c6-8d86-4357-871e-70621d09719d",
        "rowNumber": 3,
        "note": null,
        "Kundengruppe": {
            "value": "bis 25.000,-  0,00%" //
        },
        "UUID": {},
        "custom": {}
}

ASPX & Data class attribute for custom field Kundengruppe

<px:PXDropDown runat="server" ID="CstPXDropDown40" DataField="UsrKundengruppe" CommitChanges="True" Enabled="True" SelectMethod="" />

------

[PXDBInt]
[PXIntList(new int[] {0,1,2,3,4,5,6,7,8}, new string[] {"bis 25.000,-  0,00%", "25.001,- bis 50.000,- 3,75%", "50.001,- bis 100.000,- 7,50%", "100.001,- bis 200.000,-  10,00%", "200.001,- bis 300.000,- 12,00%", "300.001,- bis 500.000,- 14,50%", "500.001,- bis 750.000,-  16,50%", "750.001,- bis 1.000.000,- 18,50%", "ab 1.000.000,- 20,00%"})]
[PXUIField(DisplayName="Kundengruppe Jahresumsatz von - bis Rabatt")]

Screenshots of some screens Dropdown list, Element properties

Is there anyway to fixing this? I am not really familiar with C# in general. I also made a new fresh Endpoint to specifically for this custom field.

Note: I am using german localized version of Acumatica called Haufe x360



Solution 1:[1]

You need to set the data type on the web service endpoint screen, it defaults to string regardless of the column type:

enter image description here

Solution 2:[2]

I looked at the backend SQL Server tables for a stock PXDropDown (i.e. Shipping Rule property in Sales Order). If you set the Shipping Rule to "Ship Complete", then this sets "Ship Complete" in the database table as well. However, if you use a PXSelector, then the value is stored by reference in the database.

I don't think you are going to be able to do what you want to do with a PXDropDown. The framework doesn't have a way to go from the stored text database value back to the index value, and the REST API is just looking at what's in the database for the most part.

I would say change it to a PXSelector. Or you could write a graph extension that grabs the attribute values for the PXDropdown and saves the reference value to the database instead of the text value/saves it to another custom field (although you would have to make sure that the referential integrity will hold....for example if you add another dropdown value and that becomes value #1, then you've broken your referential integrity to the previous #1 value). The bottom line is that this can be done with a graph extension and a little bit of planning, but that will require C# code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kyle Vanderstoep
Solution 2 user1576945