on 2024 Jul 03 10:01 PM
Hi,
Is there a way to open the business object in Edit mode after clicking a custom action (e.g., Reset button)? The reset button currently has 2 purposes, first is to clear the screen and the other is to open the object in Edit Mode (i.e., Draft State).
I know that we can simply click the Edit button and subsequently click Reset button or vice versa, we are just wondering if it is feasible to do it in a single button click.
I tried applying the logic based on Ramjee's tutorial (https://community.sap.com/t5/technology-blogs-by-members/abap-restful-application-programming-enabli...) but I am getting this error message (although in the background, the draft instance has been created):
I suspect it has something to do with the URL parameters:
Before clicking Reset button, the UNAME field is filled up with the username value which is the key for this business object.
&sap-client=100#/zc_fileupload(Uname='RBALAGTA',IsActiveEntity=true)
However, after clicking the Reset button (and refreshing the screen via side effects), the uname field became blank.
&sap-client=100#/zc_fileupload(Uname='',IsActiveEntity=false)
Here is my code for the Reset action implementation:
READ ENTITIES OF zi_fileupload IN LOCAL MODE
ENTITY Upload
ALL FIELDS
WITH CORRESPONDING #( keys )
RESULT DATA(lt_file)
ENTITY Upload BY \_Output
ALL FIELDS
WITH CORRESPONDING #( keys )
RESULT DATA(lt_output).
MODIFY ENTITIES OF zi_fileupload IN LOCAL MODE
ENTITY Upload
EXECUTE edit FROM
VALUE #( FOR <fs_active_key> IN keys WHERE ( %is_draft = if_abap_behv=>mk-off )
( %key = <fs_active_key>-%key
%cid = 'RBALAGTA'
%param-preserve_changes = 'X' ) )
REPORTED DATA(edit_reported)
FAILED DATA(edit_failed)
MAPPED DATA(edit_mapped).
DATA(lt_keys) = keys.
LOOP AT lt_keys ASSIGNING FIELD-SYMBOL(<ls_key>).
<ls_key>-%is_draft = if_abap_behv=>mk-on.
ENDLOOP.
READ ENTITIES OF zi_fileupload IN LOCAL MODE
ENTITY Upload
ALL FIELDS
WITH CORRESPONDING #( lt_keys )
RESULT lt_file.
MODIFY ENTITIES OF zi_fileupload IN LOCAL MODE
ENTITY Upload
UPDATE
FIELDS ( Status
Input1
Input2
Input3
Input4
Input5
Attachment
Filename
Mimetype
Hideexcel
Updatedata
)
WITH VALUE #( FOR <fs_rec_draft> IN lt_file ( %tky = <fs_rec_draft>-%tky
%is_draft = '01'
Status = 'R'
Input1 = ''
Input2 = ''
Input3 = ''
Input4 = ''
Input5 = ''
Attachment = ''
Filename = ''
Mimetype = ''
Hideexcel = ''
Updatedata = abap_false
%control-Status = if_abap_behv=>mk-on
%control-Input1 = if_abap_behv=>mk-on
%control-Input2 = if_abap_behv=>mk-on
%control-Input3 = if_abap_behv=>mk-on
%control-Input4 = if_abap_behv=>mk-on
%control-Input5 = if_abap_behv=>mk-on
%control-Attachment = if_abap_behv=>mk-on
%control-Filename = if_abap_behv=>mk-on
%control-Mimetype = if_abap_behv=>mk-on
%control-Hideexcel = if_abap_behv=>mk-on
%control-UpdateData = if_abap_behv=>mk-on ) )
ENTITY Output
DELETE FROM VALUE #( FOR ls_output IN lt_output ( %key = ls_output-%key ) )
REPORTED edit_reported
FAILED edit_failed
MAPPED DATA(lt_updated).
READ ENTITIES OF zi_fileupload IN LOCAL MODE
ENTITY Upload
ALL FIELDS
WITH CORRESPONDING #( lt_keys )
RESULT DATA(lt_new_file).
result = VALUE #( FOR ls_file IN lt_new_file
( %tky = ls_file-%tky
%param = ls_file ) ).
I have added also the behavior definition below.a
managed implementation in class zbp_i_fileupload unique;
strict ( 2 );
with draft;
define behavior for zi_fileupload alias Upload
with unmanaged save with full data
draft table zdfileupload
etag master uname
lock master
total etag uname
authorization master ( global )
{
field ( readonly ) Uname, Input6;
field ( mandatory ) Input1;
internal create;
update;
delete;
association _output { internal create; with draft; }
association _Parameters { create; with draft; }
action processRecords result [1] entity zi_fileupload;
action (lock : none) resetScreen result [1] entity zi_fileupload;
// action (lock : none) resetScreen;
validation validateInput on save { create; update; }
validation validateInput1 on save { create; field Input1; }
validation validateAttachment on save { create; field Attachment; }
determine action valdetInput1 { validation validateInput1; }
determine action valdetAttachment { validation validateAttachment; }
side effects {
action resetScreen affects $self, entity _output;
action processRecords affects entity _output;
determine action valdetInput1 executed on field Input1 affects messages;
determine action valdetAttachment executed on field Attachment affects messages;
}
draft action Edit;
draft action Activate optimized;
draft action Discard;
draft action Resume;
draft determine action Prepare
{
validation validateInput;
validation ( always ) validateInput1;
validation ( always ) validateAttachment;
}
}
define behavior for zi_fileoutput alias Output
with additional save
persistent table zfilecontent
draft table zdfilecontent
lock dependent by _File
authorization dependent by _File
etag master uname
{
internal update;
internal delete;
action processData result [0..*] $self;
field ( readonly ) uname, sequence;
association _File { with draft; }
side effects {
action processData affects $self;
}
}
define behavior for zi_uploadparams alias Parameters
with unmanaged save with full data
draft table zduploadparams
lock dependent by _File
authorization dependent by _File
etag master uname
{
internal update;
internal delete;
field ( readonly ) uname, sequence;
association _File { with draft; }
}
Request clarification before answering.
Any luck? Even I have same scenario.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.