# Sales Order Contact # confusion

**URL:** <https://www.epiusers.help/t/sales-order-contact-confusion/100790>\
**Category:** Kinetic ERP\
**Tags:** baq, reports, epicor\
**Created:** [March 20, 2023, 1:49pm UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790 "2023-03-20T13:49:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![markamiller](https://www.epiusers.help/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@markamiller](https://www.epiusers.help/u/markamiller)\
**Post date:** [March 20, 2023, 1:49pm UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/1 "2023-03-20T13:49:13Z")

</div>

I am stumped and hope someone can help me. I need to get the email address of the Sold To: Attn contact on the sales order. Field Help says the field that stores this value is OrderHed.PrcConNum. No matter what name I select from the drop down the number is always 1.

To make things worse, when I join the Orderhed table to CustCont table using CustNum-\>CustNum and PrcConNum-\>ConNum I get 2 rows.

Any help would be greatly appreciated… Thanks.

---

<div class="post-metadata">

**Author:** ![andrew.johnson](https://www.epiusers.help/user_avatar/www.epiusers.help/andrew.johnson/32/61226_2.png) [@andrew.johnson](https://www.epiusers.help/u/andrew.johnson)\
**Post date:** [March 20, 2023, 1:52pm UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/2 "2023-03-20T13:52:22Z")

</div>

Include the ShipTo value in your join. If a customer has multiple ShipTos, and contacts per ShipTo, you will get multiple results.

---

<div class="post-metadata">

**Author:** ![markamiller](https://www.epiusers.help/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@markamiller](https://www.epiusers.help/u/markamiller)\
**Post date:** [March 20, 2023, 2:00pm UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/3 "2023-03-20T14:00:01Z")

</div>

Thanks Andrew for the help. I did as I understood you to say…

select  
[OrderHed].[PrcConNum] as [OrderHed\_PrcConNum],  
[CustCnt].[ConNum] as [CustCnt\_ConNum]  
from Erp.OrderHed as OrderHed  
inner join Erp.CustCnt as CustCnt on  
OrderHed.CustNum = CustCnt.CustNum  
and OrderHed.PrcConNum = CustCnt.ConNum  
and OrderHed.ShipToNum = CustCnt.ShipToNum  
where (OrderHed.OrderNum = 1344)

Now now records are returned… Could something be messed up with my customer record?

Thanks Again.

---

<div class="post-metadata">

**Author:** ![markamiller](https://www.epiusers.help/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@markamiller](https://www.epiusers.help/u/markamiller)\
**Post date:** [March 20, 2023, 2:01pm UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/4 "2023-03-20T14:01:50Z")

</div>

To be more clear… I am trying to return the Sold To: Attn contact email address

---

<div class="post-metadata">

**Author:** ![andrew.johnson](https://www.epiusers.help/user_avatar/www.epiusers.help/andrew.johnson/32/61226_2.png) [@andrew.johnson](https://www.epiusers.help/u/andrew.johnson)\
**Post date:** [March 20, 2023, 2:06pm UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/5 "2023-03-20T14:06:02Z")

</div>

Your query looks correct. It’s good practice to always include the Company field in any joins as well, but with it missing, that doesn’t explain you getting no results.

Here’s my query:

```auto
select 
	[OrderHed].[Company] as [OrderHed_Company],
	[OrderHed].[OrderNum] as [OrderHed_OrderNum],
	[OrderHed].[CustNum] as [OrderHed_CustNum],
    [OrderHed].[ShipToNum] as [OrderHed_ShipToNum],
	[OrderHed].[PrcConNum] as [OrderHed_PrcConNum],
	[OrderHed].[ShpConNum] as [OrderHed_ShpConNum],
	[CustCnt].[Name] as [CustCnt_Name],
	[CustCnt].[EMailAddress] as [CustCnt_EMailAddress]
from Erp.OrderHed as OrderHed
inner join Erp.CustCnt as CustCnt on 
	OrderHed.Company = CustCnt.Company
	and OrderHed.CustNum = CustCnt.CustNum
	and OrderHed.ShipToNum = CustCnt.ShipToNum
	and OrderHed.PrcConNum = CustCnt.ConNum

```

![image](https://www.epiusers.help/uploads/default/original/3X/0/7/073596fb0d6f58d14ed34a2ff79d08a9ef709302.png)

---

<div class="post-metadata">

**Author:** ![jkane](https://www.epiusers.help/user_avatar/www.epiusers.help/jkane/32/57624_2.png) [@jkane](https://www.epiusers.help/u/jkane)\
**Post date:** [March 20, 2023, 2:12pm UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/6 "2023-03-20T14:12:17Z")

</div>

The Sold To contacts are located here on the Customer record. If you do not have any contact records here, they will not show up on the Order.

![image](https://www.epiusers.help/uploads/default/original/3X/c/3/c3fa00e319eacbb6a4a6dbf2e14e894074b12c5d.png)

---

<div class="post-metadata">

**Author:** ![markamiller](https://www.epiusers.help/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@markamiller](https://www.epiusers.help/u/markamiller)\
**Post date:** [March 21, 2023, 1:00pm UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/7 "2023-03-21T13:00:34Z")

</div>

Thanks for your help. Greatly appreciated.

I did a trace on the GetList method on the Sales Order screen. The query in the trace showed ShipToNum=“” So, i changed my query to:  
select  
[CustCnt].[CustNum] as [CustCnt\_CustNum],  
[CustCnt].[ConNum] as [CustCnt\_ConNum],  
[OrderHed].[ShipToNum] as [OrderHed\_ShipToNum],  
[CustCnt].[ShipToNum] as [CustCnt\_ShipToNum],  
[CustCnt].[Name] as [CustCnt\_Name]  
from Erp.OrderHed as OrderHed  
inner join Erp.CustCnt as CustCnt on  
OrderHed.CustNum = CustCnt.CustNum  
and OrderHed.PrcConNum = CustCnt.ConNum  
and ( CustCnt.ShipToNum = ‘“”’ )

where (OrderHed.OrderNum = 1344)

Realized the other record being displayed was the Primary Ship To Contact. The CustCnt.ConNum for that row was 1 as well.

Sanity check! Thanks

---

<div class="post-metadata">

**Author:** ![Paras\_Sood](https://www.epiusers.help/user_avatar/www.epiusers.help/paras_sood/32/68228_2.png) [@Paras\_Sood](https://www.epiusers.help/u/Paras_Sood)\
**Post date:** [July 1, 2024, 12:13am UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/8 "2024-07-01T00:13:07Z")

</div>

That is a bandaid fix but not a real solution.

This solution will fail as soon as you do have a value in the custcnt.shiptonum field.

I just feel that the way the database is designed for custcnt is quite clunky. Company, ShipTo, CustID and ConNum are the primary keys, where it would have been much easier for me if only ConNum was the PK and unique for each entry.

In my environment, the sales staff haven’t setup the ship to addresses correctly. Moreover, the ship to address on the sales order may be different from the address stored in the contact person’s ID. So a join including Ship To leads to nothing.

Does anyone have a solution for this?

That being said, I don’t understand how it’s working in Epicor, since the UI is loading the correct field. How does the UI identify that it’s correct?

This is my query:

```auto
select 
       [OrderHed].[OrderNum] as [OrderHed_OrderNum],
       [OrderHed].[PONum] as [OrderHed_PONum],
       [OrderDtl].[POLine] as [OrderDtl_POLine],
       [CustCnt].[Name] as [CustCnt_Name],
       [CustCnt].[City] as [CustCnt_City],
       [OrderDtl].[XPartNum] as [OrderDtl_XPartNum],
       [OrderDtl].[PartNum] as [OrderDtl_PartNum],
       [OrderDtl].[LineDesc] as [OrderDtl_LineDesc],
       [OrderDtl].[SellingQuantity] as [OrderDtl_SellingQuantity],
       [OrderDtl].[SalesUM] as [OrderDtl_SalesUM],
       [OrderHed].[OrderDate] as [OrderHed_OrderDate],
       [OrderDtl].[RequestDate] as [OrderDtl_RequestDate],
       [OrderHed].[NeedByDate] as [OrderHed_NeedByDate]
from Erp.Customer as Customer
inner join Erp.OrderHed as OrderHed on 
       Customer.Company = OrderHed.Company
       and Customer.CustNum = OrderHed.BTCustNum
       and ( OrderHed.OpenOrder = 1)

inner join Erp.OrderDtl as OrderDtl on 
       OrderHed.Company = OrderDtl.Company
       and OrderHed.OrderNum = OrderDtl.OrderNum
       and ( OrderDtl.OpenLine = 1)

inner join Erp.CustCnt as CustCnt on 
       OrderHed.Company = CustCnt.Company
       and OrderHed.CustNum = CustCnt.CustNum
       and OrderHed.PrcConNum = CustCnt.ConNum
where (Customer.CustID = 'P_ERGON') AND OrderHed.OrderNum=2352576
ORDER BY OrderHed_OrderNum;

```

Issue:

ContactID will reset if a ship to num is there.

Therefore you can have entry as follows:  
1,2,0,1;  
1,2,0,2;  
1,2,1,1;

Currently the join between Order Header and Customer Contact is on Company, Customer ID and Contact ID, I am getting duplicates.

So, Because we are joining on the first second and fourth column, we get duplicates in the first entry and the third entry.

---

<div class="post-metadata">

**Author:** ![jkane](https://www.epiusers.help/user_avatar/www.epiusers.help/jkane/32/57624_2.png) [@jkane](https://www.epiusers.help/u/jkane)\
**Post date:** [July 1, 2024, 1:15am UTC](https://www.epiusers.help/t/sales-order-contact-confusion/100790/9 "2024-07-01T01:15:44Z")

</div>

~~Not at my computer, so I would have to double check tomorrow morning.~~

~~I think you need to join on Customer.CustNum = OrderHed.CustNum. And not on BTCustNum. CustNum is the “base” customer number on all records. The bill to can be a completely different customer all together.~~

I read it again. There are two different levels of contacts on the customer. The sold to and the bill to has one level and the ship to is the other level. When you need a sold to or bill to contact, you join on company, custnum, and connum. In this instance, the ship to will always be empty. You only join on ship to when needing a ship to contract.
