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 be in 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: |
Step 2 | In the Data Provider Class, in the WHEN 'ReferenceSet'. me->get_referenceset( IMPORTING et_entityset = et_entityset ). |
Step 3 | Create a new method called METHOD get_referenceset. 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. DEFINE move_field. UNASSIGN <fs_any>. ASSIGN COMPONENT &1 of STRUCTURE <fs_results> to <fs_any>. if <fs_any> is ASSIGNED. <fs_any> = &2. endif. END-OF-DEFINITION. DEFINE _read_filter_low. CALL METHOD me->read_filter_low_value EXPORTING i_field = &1 IMPORTING e_value = &2. END-OF-DEFINITION. READ TABLE gt_filter WITH TABLE KEY property = 'ProjectName' INTO ls_filter. IF sy-subrc IS INITIAL. LOOP AT ls_filter-select_options INTO ls_seloption. lv_project = ls_seloption-low. CLEAR ls_seloption. ENDLOOP. ENDIF. READ TABLE gt_filter WITH TABLE KEY property = 'SubmittedByUname' INTO ls_filter. IF sy-subrc IS INITIAL. LOOP AT ls_filter-select_options INTO ls_seloption. lv_uname = ls_seloption-low. CLEAR ls_seloption. ENDLOOP. ENDIF. IF lv_uname IS INITIAL. lv_uname = sy-uname. ENDIF. READ TABLE gt_filter WITH TABLE KEY property = 'Attribute1' INTO ls_filter. IF sy-subrc IS INITIAL. 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. CLEAR ls_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. CLEAR ls_instance. ENDLOOP. ENDMETHOD. |
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. Notable properties:
Note that in this example, SearchValue4 was used - you may choose to use a different search parameter if your form fills that value.
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. 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, CASE i_action. 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. |