cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign a reference on a Customer Return for a Sales Order that doesn't exist?

Former Member

I'm currently working on a customization for a client that enters extremely large Customer Returns (several hundred items). Many of the items on the Return can't be linked to existing Sales Orders in ByDesign (i.e. the originating Sales Order).

In the event that they can't determine the Sales Order, they populate it with "NA" or "UNKNOWN" using the "Assign Reference" button on the return screen. However, they have to do this one-by-one. This method works, though, provided it's done in the front-end.

I'm trying to write code to automate this, but both methods that i would expect to work return errors, even though i'm populating data elements identically to what appears in the back-end query when looking at one that was done manually.

Does anyone know the correct method for this?

Here's the code i have so far - running on the CustomerReturn object, BeforeSave event:

import ABSL;
import AP.CRM.Global;
import AP.Common.GDT;
import AP.Common.Global;

//For Each Item Without A Reference
foreach (var FoundItemWithoutReference in this.Item) {
    //If The Base Business Transaction Document Reference Does Not Yet Exist
    if (!FoundItemWithoutReference.BaseItemBusinessTransactionDocumentItemReference.IsSet()) {

        //AddReferenceWithDataProvision Does Not Work
        //The Below Code Will Return The Error - "Copying document not possible; reference document does not exist"
        var BusinessTransactionDocumentItemKey : BusinessTransactionDocumentItemKey;
        BusinessTransactionDocumentItemKey.BusinessTransactionDocumentItemID = "UNKNOWN";
        BusinessTransactionDocumentItemKey.BusinessTransactionDocumentKey.BusinessTransactionDocumentID.content = "UNKNOWN";
        BusinessTransactionDocumentItemKey.BusinessTransactionDocumentKey.BusinessTransactionDocumentTypeCode = "28";
        FoundItemWithoutReference.AddReferenceWithDataProvision(BusinessTransactionDocumentItemKey);

        //The Below Code Will Return The Error - "Create not possible; source object inconsistent"

        //Create The Blank Business Transaction Document Reference
        var BTDR_TypeCode : BusinessTransactionDocumentTypeCode;
        var BTDR_ID : BusinessTransactionDocumentID;
        var BTDR_ItemTypeCode : BusinessTransactionDocumentItemTypeCode;
        var BTDR_ItemID : BusinessTransactionDocumentItemID;
        BTDR_TypeCode = "114";
        BTDR_ID.content = "UNKNOWN";
        BTDR_ItemTypeCode = "28";
        BTDR_ItemID = "UNKNOWN";
        //Store The Elementsof The To-Be-Created Sales Order Item Reference
        var elemItemBusinessTransactionDocumentReference : elementsof CustomerReturn.Item.ItemBusinessTransactionDocumentReference;
        elemItemBusinessTransactionDocumentReference.BusinessTransactionDocumentRelationshipRoleCode = "1"; //Role Code 1 - Predecessor
        elemItemBusinessTransactionDocumentReference.BusinessTransactionDocumentReference.TypeCode = BTDR_TypeCode;
        elemItemBusinessTransactionDocumentReference.BusinessTransactionDocumentReference.ID = BTDR_ID;
        elemItemBusinessTransactionDocumentReference.BusinessTransactionDocumentReference.ItemTypeCode = BTDR_ItemTypeCode;
        elemItemBusinessTransactionDocumentReference.BusinessTransactionDocumentReference.ItemID = BTDR_ItemID;
        elemItemBusinessTransactionDocumentReference.DataProviderIndicator = false; //Data Provider - False, This Is Not A ByDesign Transaction
        FoundItemWithoutReference.ItemBusinessTransactionDocumentReference.Create(elemItemBusinessTransactionDocumentReference);

    } //End If The Base Business Transaction Document Reference Does Not Yet Exist
} //End For Each Item Without A Reference

Accepted Solutions (0)

Answers (5)

Answers (5)

HorstSchaude
Product and Topic Expert
Product and Topic Expert

Hello Pierre,

Sorry, but I have left this area. 😞

But AFAI remember there was nothing done in this direction.

Bye,
. Horst

HorstSchaude
Product and Topic Expert
Product and Topic Expert

Hello Dan,

If there is no reference why do you need to create one at all?
Do you get an error too if there is no "ItemBusinessTransactionDocumentReference" created?

Bye,
Horst

Former Member
0 Kudos

Horst,

Yes, a reference is required - without it, the return is invalid/inconsistent and can't be posted.

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Pierre,

Sorry, but I am no longer within the PDI topic.

AFAIK there was no update here.

Bye,
. Horst

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Dan,

So you can now tell the support that even the SCN does not know an answer. 😞

Sorry,
Horst

leveau1
Explorer
0 Kudos

Hello Horst, Any update regarding this issue?

The only thing missing from the PDI method is the External Indicator-checkbox which lets you pass any information into these fields.

Regards,
Pierre

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Dan,

Based on your coding a BTD refrence with the ID "UNKNOWN" must exist if you submit those data. 😞

What about leaving the ID fields empty?

Bye,
Horst

Former Member
0 Kudos

Horst,

Good thought, but i get the same error. I figured as much, but when i opened a case with support, they told me that i had to ask the question on the SCN before they'd consider it. I'll send it back to SAP.

Thanks for replying,

-Dan