How do you join a Work Order to the Sales Order Line Item for which it was created in Crystal Reports?

SOLVED

Trying to write a report that shows Sales Order line items and any Work Orders that have been created for them.  I thought I had it when I joined these tables:

SO_SalesOrderDetail to WO1_WorkOrderMaster on SO.SalesOrderNo = WO.MakeForOrderNumber and SO.LineKey = WO.SOLineIndex

But apparently a line index is not the same thing as a line key.  I believe the line key is a unique number assigned at entry that never changes, while the index is just its current position.  The line key field doesn't appear to be in the WO1_WorkOrderMaster table.  I do see it in the WO_WorkOrder table but that seems to be an empty file.  Adding Item Code and Qty would not be unique enough because sometimes we have multiple lines for same item/qty in one order.

Is this even possible?  I really hope so and I'd greatly appreciate your help!

Thank you!

  • 0

    I've heard that it's likely you would know the answer to this.  Would you mind taking a look?  Thank you so much!

  • 0
    SUGGESTED

    SELECT "SO_SalesOrderDetail"."SalesOrderNo", "SO_SalesOrderDetail"."ItemCode", "WO1_WorkOrderMaster"."WorkOrder", "WO1_WorkOrderMaster"."MakeForOrderNumber", "WO1_WorkOrderMaster"."SOLineIndex", "SO_SalesOrderDetail"."LineKey"
    FROM "SO_SalesOrderDetail" "SO_SalesOrderDetail", "WO1_WorkOrderMaster" "WO1_WorkOrderMaster"
    WHERE ((("SO_SalesOrderDetail"."SalesOrderNo"="WO1_WorkOrderMaster"."MakeForOrderNumber") AND ("SO_SalesOrderDetail"."ItemCode"="WO1_WorkOrderMaster"."ItemBillNumber")) AND ("SO_SalesOrderDetail"."LineKey"="WO1_WorkOrderMaster"."SOLineIndex"))

  • 0 in reply to Tyler Christensen

    Thank you, Tyler, but Item Code is not unique in a Sales Order (for us, anyway) and I don't think Line Key is the same thing as Line Index.  They might be the same initially, but as you add, delete, or ship lines they do not stay in sync.  I tried that and it matched to incorrect records.

  • 0 in reply to AgentCunningham

    If you add lines, the LineKey will be a new number that will be higher than the last line key on the order so I don't think it will be a problem if you link on this field since it does not change as you add or delete lines.  I was just playing with it now and it just kept incrementing up so since it stays the same I would think you could link on them just fine.  In fact, I don't even think you need to link the item code on SO to bill number in WO.  By definition if you link of the SO number to the WO MakeForOrderNumber and the SO Line Key to WO SOLineIndex I think you will be fine.

  • 0 in reply to AgentCunningham

    Hi, Tyler's response below is correct.


    The SO_SalesOrderDetail.LineKey =  WO1_WorkOrderMaster.SOLineIndex

    Select SO.SalesOrderNo, WO1.WorkOrder, WO1.ItemBillDescription, WO1.QtyOrdered 
    From SO_SalesOrderDetail SO, WO1_WorkOrderMaster WO1
    Where WO1.MakeForOrderNumber = SO.SalesOrderNo and SO.LineKey = WO1.SOLineIndex

    Thanks

    John Nichols

    Sage

  • +1 in reply to Tyler Christensen
    verified answer

    Hi Tyler - thank you so much for spending time on this!  I looked at all the files involved and here is what I found.  We originally had 3 line items in the SO, with lines 2 and 3 having associated Work Orders.  We completed the WOs and shipped those 2 lines, but line 1 was back ordered.  Then we added a new line to the SO, which did not need a WO, and it received line key 2 - a duplicate of the original line key 2 that was already shipped.  That is why there is a WO record falsely matching to the new line 2 and appearing on my report.  I would think that the line key would be kept unique even through adding, deleting, and shipping lines, but apparently not.  Looks like it just takes the highest line key in the order as it sits at the time, and adds 1.  This makes it impossible to be confident in the report.  I can add Item Code and Order Qty to the join criteria, but it still won't be 100% - maybe 99%.  Thanks again, and please let me know if you find anything that contradicts my findings.  -Tony Cunningham

  • +1 in reply to jcnichols
    verified answer

    Hello John - Thank you so much for looking at this.  I think the LineKey matches the SoLineIndex most of the time, but here is what I found:  Quoting my reply to Tyler: 

    I looked at all the files involved and here is what I found.  We originally had 3 line items in the SO, with lines 2 and 3 having associated Work Orders.  We completed the WOs and shipped those 2 lines, but line 1 was back ordered.  Then we added a new line to the SO, which did not need a WO, and it received line key 2 - a duplicate of the original line key 2 that was already shipped.  That is why there is a WO record falsely matching to the new line 2 and appearing on my report.  I would think that the line key would be kept unique even through adding, deleting, and shipping lines, but apparently not.  Looks like it just takes the highest line key in the order as it sits at the time, and adds 1.  This makes it impossible to be confident in the report.  I can add Item Code and Order Qty to the join criteria, but it still won't be 100% - maybe 99%. 

    Best regards,

    Tony Cunningham

  • 0 in reply to AgentCunningham

    Turn on the SO Option to retain deleted lines in SO history, and you shouldn't have any more problems with repeated line keys.

  • 0 in reply to Kevin M

    Hi Kevin - thank you for your help.  Here is a screenshot of our history options.  The shipped line items are being retained.  Deleted items are prompted, but we're not dealing with deleted lines in this scenario, they are shipped.  I've also attached a report with the line items in question, pulling data from SO_SalesOrderHistoryDetail and SO_SalesOrderHistoryHeader to show all lines are in history and LineKey 2 was duplicated.  Thoughts?  Thanks again, Tony

  • 0 in reply to Kevin M

    Wait a sec... now I'm not sure where that last line came from.  It's the same item code as the first line and the first line shipped 2,000 out of 4,000 on order, but the back order qty is 0. How does that happen?  It doesn't matter much, though.  Whether it was auto-created by Sage or manually added, it shouldn't duplicate a line key from history, should it?  Remaining Open Line Item attached in case it helps.

    Open Line Item

    WO record from original LineKey2 that is incorrectly matching to remaining open line item is shown here: