Following is the case when you open the create travel request application and click on “+” symbol to create a new request. There is a currency field in the create form which is after the input field for Estimated Cost.
Requirement was to fill the default currency applicable to the user as shown in the below image
Next thing was to look into the code of this application. View corresponding to this was DetailForm View.
Code corresponding to the view was
<Input
id="Trc_SC_Currency"
value="{EstimatedCost/Currency}"
showValueHelp="true"
editable="{ parts:[{path:'UserInfo>/GlobalSettings>/FixedCurrency'}] , formatter : '.checkGlobalSettingsFixedCurrency'}"
showSuggestion="true"
suggestionItems="{Currencies>/result}"
valueHelpRequest="onCurrencyValueHelpRequest">
<suggestionItems>
<core:Itemtext="{Currencies>Id}"></core:Item>
</suggestionItems>
</Input>
As we can see the editable property if already having mapping to some value. We map it to the field which will be filled by us in the backend using our own logic for the user and also we need to change the logic in function for formatter (checkGlobalSettingsFixedCurrency).
So extended view will have the currency field as below
<Input
id="Trc_SC_Currency"
value="{EstimatedCost/Currency}"
showValueHelp="true"
editable="{ parts:[{paxth:'UserInfo>/Currency'}] , formatter : '.checkGlobalSettingsFixedCurrency'}"
showSuggestion="true"
suggestionItems="{Currencies>/result}"
valueHelpRequest="onCurrencyValueHelpRequest">
<suggestionItems>
<core:Itemtext="{Currencies>Id}"></core:Item>
</suggestionItems>
</Input>
Changing the formatter function also as below
checkGlobalSettingsFixedCurrency : function() {
var UserInfo = this.getUserInfo();
if(UserInfo.Currency)
{
returnfalse;
}
else
{
returntrue;
}
},
The above should be enough for the UI side. Now we need to fill the default currency in the placeholder for the user info.
For fetching the default currency for the employee using odata, we used the Enhancement Spot SRA004_MY_TRAVEL_REQUEST.
Its implementation will provide you a
method (“IF_SRA004_BADI_MY_TRAVEL_REQ~CHANGE_EMPLOYEE”)
for changing the user profile. We will fetch the default currency for the user’s assigned cost center and send it in the currency field for the Employee.
Following is the code we used.
METHOD if_sra004_badi_my_travel_req~change_employee.
data: lt_return type bapireturn,
lt_return2 type bapiret1,
ls_return type bapiret2,
ls_org_assignement type bapip0001b,
lt_org_assignment like table of ls_org_assignement,
ls_personal_data type bapip0002b,
lt_personal_data like table of ls_personal_data,
ls_internal_control type bapip0032b,
lt_internal_control like table of ls_internal_control,
lt_return3 type standard table of bapiret2,
ls_costcenterdetails type bapi0012_ccoutputlist.
CALL FUNCTION 'BAPI_EMPLOYEE_GETDATA'
EXPORTING
employee_id = is_employee-id
IMPORTING
return = lt_return
TABLES
org_assignment = lt_org_assignment
personal_data = lt_personal_data
internal_control = lt_internal_control.
READ TABLE lt_org_assignment INDEX 1 INTO ls_org_assignement.
IF sy-subrc EQ 0.
is_employee-costcenter = ls_org_assignement-costcenter.
is_employee-companycode = ls_org_assignement-comp_code.
CALL FUNCTION 'BAPI_COSTCENTER_GETDETAIL1'
EXPORTING
controllingarea = ls_org_assignement-co_area
costcenter = is_employee-costcenter
IMPORTING
costcenterdetail = ls_costcenterdetails
TABLES
return = lt_return3.
is_employee-costcentername = ls_costcenterdetails-name.
CALL FUNCTION 'HRCA_COMPANYCODE_GETDETAIL'
EXPORTING
companycode = is_employee-companycode
IMPORTING
currency = is_employee-currency.
IF sy-subrc <> 0.
ENDIF.
ENDIF.
ENDMETHOD.
This provides us the required default currency and it is passed through the odata service to the UI screen.
Hope it will be useful for someone.
Regards,