Skip to Content
0

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

Oct 24, 2016 at 03:18 PM

159

avatar image
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
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
0

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

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

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

0
Horst Schaude
Nov 02, 2016 at 08:14 AM
0

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

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

Horst,

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

0
Horst Schaude
Nov 03, 2016 at 02:21 PM
0

Hello Dan,

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

Sorry,
Horst

Share
10 |10000 characters needed characters left characters exceeded