Skip to Content
1
Former Member
Mar 16, 2010 at 10:17 PM

Reading Numeric UDF null value in DI

85 Views

We have a UDF of Numeric(4) that can be NULL, 0, 1, 2, etc. We try to read it from DI, and if it is NULL, then set the result to be -1 (the default value we difined), so we can differentiate NULL and 0.

The C# code we have look like this:

int LineNumber = -1;
SAPbobsCOM.Company oCompany;
// Code to get Company

SAPbobsCOM.Documents oDoc = oCompany.GetBusinessObject(BoObjectTypes.oQuotations);

oDoc.GetByKey(100); // Get the document by DocEntry

LineNumber = (int)oDoc.UserFields.Fields.Item("U_XX_LN").Value;

The problem is LineNumber gets 0 even if in the database U_XX_LN is NULL. We tried the code below and got the same result because oDoc.UserFields.Fields.Item("U_XX_LN").Value.ToString() always return '0' if it is NULL.

if (string.IsNullOrEmpty(oDoc.UserFields.Fields.Item("U_XX_LN").Value.ToString()))
    LineNumber = -1;
else
    LineNumber = (int)oDoc.UserFields.Fields.Item("U_XX_LN").Value;

The question is: how can we set it to default -1 if in the database the value is NULL?

Thank you,

Grace