Skip to Content

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

Oct 24, 2016 at 03:18 PM


avatar image

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";

        //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

    } //End If The Base Business Transaction Document Reference Does Not Yet Exist
} //End For Each Item Without A Reference
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Horst Schaude
Oct 25, 2016 at 11:29 AM

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?


Show 1 Share
10 |10000 characters needed characters left characters exceeded


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,


Horst Schaude
Nov 02, 2016 at 08:14 AM

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?


Show 1 Share
10 |10000 characters needed characters left characters exceeded


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

Horst Schaude
Nov 03, 2016 at 02:21 PM

Hello Dan,

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


10 |10000 characters needed characters left characters exceeded