ShipTo information hard to get on Standard Data Directive on OrderHed

So our Sales orders will sometimes have a different Ship To Customer than the Bill To Customer, and some Sales orders will have a ShipTo record for the Ship To Customer:


I am trying to show a task owner what the ship to name is:

Here is the formula I am using on the Data Directive (for my variable ShipToShipToName):
image
The formula results in a null value.

I created a BAQ with the same links:


The criteria on my OrderHed is this particular Sales Order, and here are my display fields:

The results of my BAQ are:
image

So I am expecting my formula in my Data Directive would be “TestCustomerTwo - Ship To TX” and not be null.
image
But I get this:
image

Is there a problem with my formula?

I forget the exact phrase that is needed, but you need to filter out the empty Ship To records. Once you do that, it should work.

Do I need something different than the FirstOrDefault() in my c# expression (I am weak with code)

(from x in Db.ShipTo where x.Company == ttOrderHedRow.Company && x.CustNum == ttOrderHedRow.ShipToCustNum && x.ShipToNum == ttOrderHedRow.ShipToNum select x.Name).FirstOrDefault()

I just remembered, you have to account for using the blank ship to record on both tables. I forget how to code this right now, but I will look it up as I believe I have it noted somewhere.

someVariable = (from x in Db.ShipTo
        where
            !string.IsNullOrEmpty(ttOrderHedRow.ShipToNum) &&
    	    ttOrderHedRow.ShipToCustNum != null &&
            x.Company == ttOrderHedRow.Company &&
            x.CustNum == ttOrderHedRow.ShipToCustNum &&
            x.ShipToNum == ttOrderHedRow.ShipToNum
        select
            x.Name).FirstOrDefault();

someVariable = !string.IsNullOrEmpty(someVariable) ? someVariable : "No Record Found";

Kevin,
I am weak with code, but I get this error when I try to use your code:
image

But I am not sure that is my issue. My BAQ is getting the data from the ShipTo Db table, with the same links, giving a value (that is not null).
image

I just placed Field queries in my email message so I can see the values:
image

And this is the text from the message:
image

I suspect my issue lies within the formula I am using to find the ShipToShipToName:
image

But I do not know what the issue is.

Instead of returning just the field, throw the full table in there and see how many records get returned.

I noticed an odd thing. In my formula, “… == ttOrderHedRow.ShipToNum…” that the ShipToNum was pink and not black like the other fields.
image

I was grabbing the value from here:
image
But because I had a variable with the name ShipToNum, Epicor thought I was referencing the variable and not the tt value.

So I changed my variable name from ShipToNum to Ship2Num and it changed the values in this formula:
image

I had to do the same thing with CustNum (another variable I created).

Now the formula looks like this:
image
But still no joy yet.

John,
How do I dump the whole table?

same as how you insert a field into the message, except choose table instead of field. should be right above or below the field one.

Here?
image

If so, you can choose only 1 field:
image

Yup, select them all to see all of the data and how many records are returned. I have found many times that the tt table does not actually contain the info I am looking for. Or that I am returning more than 1 row.

ADVICE: DO NOT CREATE VARIABLES WITH THE SAME NAME AS FIELDS

Success!!! Once I changed my variables (so the variable name did not match a field name), I forgot to change the Scalar variable to match my new variable name. Now that I have fixed all my variable names, I get the value I am looking for.
image

Thanks for the help forum.

1 Like

I’m sorry, I was unclear on if it was being used in a custom code block, or an expression.
It would have required some tweaking to be used in an expression.

Glad you got it all worked out though!