Weird errors when creating a shipment

I am trying to create a shipment in Sage v6.0. I did a recording first and feel like I have replicated in C#. the issue is that I get an error when trying to update the shipment detail after I add the lot numbers to an item.

        shipments.Init();

        shipmentFields.FieldByName["PROCESSCMD"].PutWithoutVerification("1");
        shipments.Process();

        shipments.Order = 1;
        _ = shipments.Exists;
        shipments.Order = 0;

        shipmentFields.FieldByName["CUSTOMER"].set_Value(order.CustomerNumber);
        shipmentFields.FieldByName["PROCESSCMD"].PutWithoutVerification("1");
        shipments.Process();

        shipmentFields.FieldByName["ORDNUMBER"].set_Value(order.OrderNumber);
        shipmentFields.FieldByName["SHIP1ORDER"].set_Value("1");
        shipments.Process();

        foreach (ShipmentOrderItem soi in order.OrderItems) {
            shipmentDetailFields.FieldByName["LINENUM"].PutWithoutVerification(-soi.LineNumber);
            shipmentDetails.Read();

            shipmentDetailFields.FieldByName["QTYSHIPPED"].set_Value(soi.QtyShipped);
            shipmentDetailFields.FieldByName["PROCESSCMD"].PutWithoutVerification("29");

            shipmentDetails.Process();

            foreach (ShipmentOrderItemLot soil in soi.Lots) {
                shipmentDetailLotNumbers.RecordClear();
                shipmentDetailLotNumbers.RecordCreate(tagViewRecordCreateEnum.VIEW_RECORD_CREATE_NOINSERT);

                shipmentDetailLotNumberFields.FieldByName["LOTNUMF"].set_Value(soil.LotNumber);
                shipmentDetailLotNumberFields.FieldByName["QTY"].PutWithoutVerification(soil.Quantity);

                try {
                    shipmentDetailLotNumbers.Insert();
                } catch {
                    return ("", ConsolidateAccPacErrors($"shipmentDetailLotNumbers.Insert ({soi.Item}) "));
                }

                shipmentDetailLotNumberFields.FieldByName["LOTNUMF"].PutWithoutVerification(soil.LotNumber);
                shipmentDetailLotNumbers.Read();
            }

            try {
                shipmentDetails.Update();
            } catch {
                return ("", ConsolidateAccPacErrors("shipmentDetails.Update"));
            }
            shipmentDetails.Read();
        }

        shipmentFields.FieldByName["PROCESSCMD"].PutWithoutVerification("4");
        shipments.Process();
        try {
            shipments.Insert();
        } catch {
            return ("", ConsolidateAccPacErrors("shipments.Insert"));
        }

        return (shipmentFields.FieldByName["SHINUMBER"].get_Value(), "");
    }

  • 0

    It looks basically correct.

    I would be interested to know if the shipment line already exists and thus the .insert is failing. Meaning that when you populate the order number in the shipment header, the view logic is creating the detail lines for you.  Maybe adjust your code for saving to be something like (warning, VB6 code incoming):

        With Detail
            If .Exists Then
                If .Dirty Then
                    .Update
                End If
            Else
                .Insert
            End If
        End With

  • 0 in reply to Django

    The item being shipped is line item #3 in the order. When I step though and hit line #22, the line number is 3 and the item is the correct item.

  • 0 in reply to Django

    Sorry, I should have had that there.

    Update Shipment Detail.  Attempt to modify a different record than was retrieved

  • 0 in reply to Rob Trainer

    Just a couple of things:

    Double check that all of the .Orders on all of the shipment views are are set to 0 before .inserts and .updates.

    Confirm that your compositions are correct.

    And I'd be tempted to comment out these two lines as they don't serve any purpose but the will possibly impact how the view is looking at the record.

                    shipmentDetailLotNumberFields.FieldByName["LOTNUMF"].PutWithoutVerification(soil.LotNumber);
                    shipmentDetailLotNumbers.Read();

  • 0 in reply to Django

    If you mean lines 40 and 41, I already tried that.

  • 0 in reply to Rob Trainer

    You didn't mention if you confirmed that all of your .order properties were set to zero before updating/inserting. This is critical.

    I'd be curious to know if shipmentDetails.Read(); returns true or not. 

    I know you said that it looks like the view is on the right record, but if the view didn't actually move to the detail record then the update will fail.

    Also, I'd be tempted to locate the correct record using the ORDDTLNUM field and the order detail line's DETAILNUM field value vs LINENUM. LINENUM will start with a arbitrary (but predictable) negative value and will have no actual relation to the order line's LINENUM field at all.

  • 0 in reply to Django

    I hadn't checked the return value, but it does return false which is surprising.

    Where do I get the DETAILNUM or are you saying to just set ORDDTLNUM to the LINENUM from the order?

  • 0 in reply to Rob Trainer

    No - the DETAILNUM field from OEORDD is a unique value across the order.

    When the shipment details are created, the OESHID.ORDDTLNUM field value is pulled from the OEORDD.DETAILNUM field. So if you're looking for a line on the sales order and you have the DETAILNUM from the order line you can use a .Browse statement on the shipment details to look for the shipment detail that is related to that specific order detail. You cannot count on the LINENUM field value for that.

    The LINENUM field values start as a negative value for records that have been created but not yet saved to the database. When the record is saved to the database, the LINENUM field value is reassigned to the record. DETAILNUM, however, doesn't change (either in order details or shipment details) so they are a better navigation record.

  • 0 in reply to Django

    I am not going to disagree with you but, the code replicates what Sage does in the recording.

  • 0 in reply to Rob Trainer

    You indicated that shipmentDetails.Read(); returned false. That means you're not properly on the record and you won't be able to update it.

    There are multiple ways to arrive at the record you want but you do need to land on it correctly.