As a developer, you may want to give users the ability to copy all the information from a previously completed request/form instance to a new instance (similar to using a template). However, certain key items (like status fields, workflow fields, etc.) should not be copied as the new form instance will them immediately be in the an incorrect state. This article demonstrates how to enable "Create an instance with reference" functionality in your FAB application.
Procedure
Step 1 | Define OData Service for Search Help |
...
. Using the Entity Set Designer in FAB, build the Entity Set as follows: Image Added |
...
Step 2 | In the Data Provider Class, in the GET_ENTITYSET method, include the following code: Code Block |
---|
WHEN 'ReferenceSet'. |
|
...
...
IMPORTING
et_entityset = et_ |
|
...
|
Step 3 | Create a new method called GET_REFERENCESET , as follows (with the same signature as the GET_ENTITYSET method): |
...
...
DATA: lt_instances TYPE TABLE OF /iqx/formhd_inst, |
|
...
ls_instance TYPE /iqx/formhd_inst, |
|
...
ls_filter TYPE /iwbep/s_mgw_select_option, |
|
...
ls_seloption TYPE /iwbep/s_cod_select_option, |
|
...
lr_search TYPE RANGE OF /iqx/search_value_short, |
|
...
ls_search LIKE LINE OF lr_search, |
|
...
lv_project TYPE /iqx/form_name, |
|
...
lv_uname TYPE uname.
FIELD-SYMBOLS: <fs_results> TYPE any. |
|
...
FIELD-SYMBOLS: <fs_any> TYPE any. |
|
...
...
...
ASSIGN COMPONENT &1 of STRUCTURE <fs_results> to <fs_any>. |
|
...
...
...
endif.
END-OF-DEFINITION. |
|
...
...
CALL METHOD me->read_filter_low_ |
|
...
value
EXPORTING
i_field = & |
|
...
1
IMPORTING
e_value = &2. |
|
...
...
READ TABLE gt_filter WITH TABLE KEY property = 'ProjectName' INTO ls_filter. |
|
...
...
LOOP AT ls_filter-select_options INTO ls_seloption. |
|
...
lv_project = ls_seloption-low. |
|
...
...
ENDLOOP.
ENDIF.
READ TABLE gt_filter WITH TABLE KEY property = 'SubmittedByUname' INTO ls_filter. |
|
...
...
LOOP AT ls_filter-select_options INTO ls_seloption. |
|
...
lv_uname = ls_seloption-low. |
|
...
...
ENDLOOP.
ENDIF.
IF lv_uname IS INITIAL. |
|
...
...
ENDIF.
READ TABLE gt_filter WITH TABLE KEY property = 'Attribute1' INTO ls_filter. |
|
...
...
LOOP AT ls_filter-select_options INTO ls_seloption. |
|
...
ls_search-sign = ls_seloption-sign. |
|
...
ls_search-option = ls_seloption-option. |
|
...
ls_search-low = ls_seloption-low. |
|
...
APPEND ls_search TO lr_search. |
|
...
...
ENDLOOP.
ENDIF.
* Retrieve the FAB instances
IF lv_project IS NOT INITIAL.
SELECT * FROM /iqx/formhd_inst INTO TABLE lt_ |
|
...
instances
WHERE zform_name EQ lv_project AND status NE space
AND status NE c_status_draft AND status NE c_status_ |
|
...
start
" AND submitted_by_uname EQ lv_ |
|
...
uname
AND deleted EQ abap_false ORDER BY submitted_timestamp DESCENDING. |
|
...
ENDIF.
LOOP AT lt_instances INTO ls_instance WHERE attribute1 IN lr_search. |
|
...
APPEND INITIAL LINE TO et_entityset ASSIGNING <fs_results>. |
|
...
move_field 'ProjectName' ls_instance-zform_name. |
|
...
move_field 'Instance' ls_instance-zinstance. |
|
...
move_field 'SubmittedByUname' ls_instance-submitted_by_uname. |
|
...
move_field 'SearchField1' ls_instance-search_field1. |
|
...
move_field 'SearchValue1' ls_instance-search_value1. |
|
...
move_field 'SearchField2' ls_instance-search_field2. |
|
...
move_field 'SearchValue2' ls_instance-search_value2. |
|
...
move_field 'SearchField3' ls_instance-search_field3. |
|
...
move_field 'SearchValue3' ls_instance-search_value3. |
|
...
move_field 'SearchField4' ls_instance-search_field4. |
|
...
move_field 'SearchValue4' ls_instance-search_value4. |
|
...
move_field 'SearchField5' ls_instance-search_field5. |
|
...
move_field 'SearchValue5' ls_instance-search_value5. |
|
...
move_field 'SearchFieldDate1' ls_instance-search_field_date. |
|
...
move_field 'SearchDate1' ls_instance-search_date. |
|
...
move_field 'SearchFieldDate2' ls_instance-search_field_date2. |
|
...
move_field 'SearchDate2' ls_instance-search_date2. |
|
...
move_field 'SearchFieldAmount' ls_instance-search_field_amount. |
|
...
move_field 'SearchAmount' ls_instance-search_amount. |
|
...
move_field 'SearchFieldCurrency' ls_instance-search_field_currency. |
|
...
move_field 'SearchCurrency' ls_instance-search_currency. |
|
...
move_field 'Attribute1' ls_instance-attribute1. |
|
...
...
|
Step 4 | Do all other requires steps to register/enable the OData service (as per normal) |
...
|
Step 5 | Add an Input Control with Custom Search Help and JavaScript |
...
Add an Input control to the form:
...
. Image AddedNotable properties: Assign a Bound Field if you want to record which instance was copied from and to pass the value into the Search Help. Add a Custom Search Help for the Input control. Your definition could look something like this
|
...
Note that in this example, SearchValue4 was used - you may choose to use a different search parameter if your form fills that value. |
...
...
Image AddedAdd an ‘Action on Change’ property to call a Script, an example of which is shown below. This script in turn calls the FAB Action to create the reference copy, and on success, clears the relevant data model, attachment and process flow fields to ensure that the new instance starts in the correct state. Note: You may choose to rather call this Script from a button click or other user interaction.
|
...
Note that you may not have to clear some fo the fields shown here, and you may have to clear other fields not shown here - it will be form-specific |
...
Code Block |
---|
onCopyReference: function(evt) {
var that = this;
var oValue = evt.getSource().getValue();
var oDescription = evt.getSource().getDescription();
var oPlanVersion = getField('Summary/PlanVersion');
var oCostElement = getField('Summary/CostElement');
var oDepArea = getField('Summary/DepreciationArea');
var oFormName = getField('Summary/FormName');
var oProcessFlow = getField('FABProcessFlow');
var oWorkflow = getField('Workflow');
var payload = {};
var actionParameters = {
showBusyDialog: true,
busyDialogMessage: "Copying from request..",
showSuccessMessage: false,
successFunction: successFunction
};
function successFunction(evt, results) {
setField('AttachmentsTable', []);
setField('Header/InternalOrderCreated', '');
setField('FABProcessFlow', oProcessFlow);
setField('CopyInstance', oDescription);
setField('CopyInstanceText', oValue);
setField('Summary/FormName', oFormName);
setField('Summary/PlanVersion', oPlanVersion);
setField('Summary/CostElement', oCostElement);
setField('Summary/DepreciationArea', oDepArea);
setField('Workflow', oWorkflow);
};
fabPerformAction("CopyReference", payload, actionParameters, null);
}, |
|
Step 6 | Implement FAB Action |
...
. In the Implementation Class, PERFORM_ACTION method, include a call to the Function Module that will copy the reference instance data for you: |
...
...
WHEN 'CopyReference'. "Note that this Action name (CopyReference)is the same name as used in the JavaScript shown above in the fabPerformAction(..) call |
|
...
DATA lv_instance TYPE /iqx/instance. |
|
...
FIELD-SYMBOLS: <fs_instance> TYPE any. |
|
...
ASSIGN COMPONENT 'COPYINSTANCE' OF STRUCTURE cr_data TO <fs_instance>. |
|
...
IF <fs_instance> IS ASSIGNED. |
|
...
lv_instance = <fs_instance>. |
|
...
ENDIF.
CALL FUNCTION '/IQX/CREATE_DATA_FROM_REF_FORM' |
|
...
EXPORTING
i_instance = lv_ |
|
...
instance
CHANGING
cr_data = cr_ |
|
...
data
ct_results = ct_results. |
|
...