cancel
Showing results for 
Search instead for 
Did you mean: 

ObjectPage not found when using factory Copy Action

HugoJ
Advisor
Advisor
0 Kudos

Hi, I'm implementing a RAP-based Fiori App, similar to the Travel app as seen in many RAP tutorials.

Currently I'm facing an issue implementing the action to Copy an instance to a new one with draft enabled. When I click the action to copy, the backend method creates the new instance in draft mode correctly, however when the Object Page of the new instance opens it shows a "The requested data was not found." message and an empty screen (see attached image - "Not Found").

I noticed in the Object Page URL that the key parameters are emtpy. If I manually fill them in the URL the object page then opens correctly (see attached image - "URL"). In my case, the missing values are in field Source and Docnr.

The implementation is similar to the one seen in this tutorial: https://developers.sap.com/tutorials/abap-environment-rap100-factory-action.html I'm using ODataV2 in SAP S/4HANA 2022 on-premise.

Summary of implementation:

- BDEF action: factory action copyDocument [1];

- BDEF projection: use action copyDocument;

- Behavior Impl: exactly like the tutorial - obviously adapted to my tables and fields. and with an added child table - see snippet at the end of the question

One final note: before using factory action, I was using a regular instance action with a result $self return and I was facing the same exact issue, so I was able to create the instance in draft but the ObjectPage URL always missed the key values in the parameters.

Thank you for your help!

Copy Method Implementation:

METHOD copyDocument.

 DATA:
documents TYPE TABLE FOR CREATE ZI_HEADER\\Header,
positions TYPE TABLE FOR CREATE ZI_HEADER\\Header\_Positions.

 READ ENTITIES OF ZI_HEADER IN LOCAL MODE
 ENTITY Header
 ALL FIELDS WITH CORRESPONDING #( keys )
 RESULT DATA(document_read_result)
 FAILED failed
 REPORTED reported.

 READ ENTITIES OF ZI_HEADER IN LOCAL MODE
 ENTITY Header BY \_Positions
 ALL FIELDS WITH CORRESPONDING #( document_read_result )
 RESULT DATA(item_read_result).

 LOOP AT document_read_result ASSIGNING FIELD-SYMBOL(<previous_doc>).
 DATA(new_docnr) = getNextDocnr( ).
 DATA(source) = getSource( ).

 APPEND VALUE #( %cid = source && new_docnr
%is_draft = '01'
%data = CORRESPONDING #( <previous_doc> EXCEPT Source Docnr ) ) TO documents ASSIGNING FIELD-SYMBOL(<new_doc>).
 APPEND VALUE #( %cid_ref = source && new_docnr
%is_draft = '01'
Source = source Docnr = new_docnr ) TO positions ASSIGNING FIELD-SYMBOL(<new_positions>).

<new_doc>-Source = source.
<new_doc>-Docnr = new_docnr.
<new_doc>-Status = order_status-new.
 GET TIME STAMP FIELD <new_doc>-Erdat.
<new_doc>-Ernam = sy-uname.

 DATA(item_position) = 10.

 LOOP AT item_read_result ASSIGNING FIELD-SYMBOL(<previous_position>) USING KEY entity
 WHERE Source EQ <previous_doc>-Source AND Docnr EQ <previous_doc>-Docnr.
 APPEND VALUE #( %cid = source && new_docnr && item_position
%is_draft = '01'
%data = CORRESPONDING #( <previous_position> EXCEPT Source Docnr ) ) TO <new_positions>-%target ASSIGNING FIELD-SYMBOL(<new_position>).
<new_position>-Source = <new_doc>-Source.
<new_position>-Docnr = <new_doc>-Docnr.
<new_position>-ItemPosition = item_position.

item_position += 10.
 ENDLOOP.
 ENDLOOP.

 MODIFY ENTITIES OF ZI_HEADER IN LOCAL MODE
 ENTITY Header
 CREATE FIELDS ( Source Docnr Status *etc* )
 WITH documents
 CREATE BY \_Positions FIELDS ( Source Docnr ItemPosition *etc* )
 WITH positions
 MAPPED DATA(mapped_create)
 FAILED DATA(failed_create)
 REPORTED DATA(reported_create).

* READ ENTITIES OF ZI_HEADER IN LOCAL MODE
* ENTITY Header
* ALL FIELDS WITH CORRESPONDING #( mapped_create-header )
* RESULT DATA(read_created_result).

mapped-header = mapped_create-header.

ENDMETHOD.
View Entire Topic
HugoJ
Advisor
Advisor

Solved. 

Issue was with field %cid - I was saving the new instance key in this field, instead of the copied instance key from the importing keys table.

Replaced:

%cid = source && new_docnr

With:

keys[ %tky = <previous_doc>-%tky ]-%cid
Nathanael
Discoverer
0 Kudos
Thank you for your question and answer! I faced a similar issue creating a static factory action. It seems to me that in order to get the filled object page after creation one always needs to use the cid provided by the RAP framework (provided in the importing parameter keys).