Page 1 of 1

Displaying Unit of Measure in sales order line

PostPosted: Thu May 21, 2020 1:14 pm
by DannyC
I just want to get whatever UOM has been selected on a sales order line.

As an intial check I am just displaying a messagebox to confirm I'm getting the right UOM.
Code: Select all
MessageBox.Show(line.UnitOfMeasure.Name);


But I am getting an error 'object reference not set to an instance of an object.'
What am I doing wrong?

Re: Displaying Unit of Measure in sales order line

PostPosted: Thu May 21, 2020 1:31 pm
by Mike.Sheen
That property is nullable, so you need to check if it is null before using it.

Re: Displaying Unit of Measure in sales order line  Topic is solved

PostPosted: Thu May 21, 2020 1:36 pm
by Scott.Pearce
A null (or nothing) UnitOfMeasure property means that "units" is used.

Code: Select all
if(line.UnitOfMeasure == null)
    MessageBox.Show(line.Units);

Re: Displaying Unit of Measure in sales order line

PostPosted: Thu May 21, 2020 2:24 pm
by DannyC
Another successful forum thread!
Thanks Mike & Scott.

This is what I did to get it working
Code: Select all
if(line.UnitOfMeasure == null)
{
    MessageBox.Show(line.Units);
}
else
{
    MessageBox.Show(line.UnitOfMeasure.Name);
}