Note
The steps below are giving a guide so that you can perform this exercise in your own system landscape.
Task 1: Establish a Connection Between BAS Workspace and Your Mobile App in Cloud Foundry
If you have not already completed this step in the exercise Setup of the Development Environment in Business Application Studio, then complete this now before you proceed with creating a custom project for extending the Mobile App.
Note
Refer to the exercise Setup Development Environment in SAP Business Application Studio in Unit 3.Your trainer provides the URL to the Business Application Studio.
Steps
Log in to Cloud Foundry.
Use Menu View → Find Command.
Choose command or type CF: Login to Cloud Foundry.
The Cloud Foundry Sign In and Targets page displays.
Enter your credentials (email_address/Password) or select Sign In or select SSO Passcode.
Choose the link and authenticate in the new tab.
Copy the code and close the tab to return.
Paste the code and choose Sign In.
Select the correct Cloud Foundry Organization. For the training, there is only one Organization, so this will default.
Select the Cloud Foundry Space. Based on the group number assigned choose the Space with the range. For example: If your group is 07 choose the space 06_10.
Choose Apply.
Once you establish the connection to the Mobile App, the BAS workspace will then use this for:
- MDK Deploy: Deployment of MDK Metadata to the appropriate app.
- Sync Service: Mobile Connections/Destinations created within the App are used for Sync the Metadata changes from the back end.
Note
At the time of the MDK Deploy or Sync Service you are prompted to choose the Mobile App. Make sure to choose your own app based on the group assigned to you.
Task 2: Create a Custom Component (New MDK Project)
Steps
Create a ZSAMComponent project for the custom component.
Log in to SAP Business Application Studio.
Once within the BAS, create a new project via Menu File → New Project from Template.
Note
By default the new project is created in /home/user/projects same as the AssetManager Project.
On the next page of Wizard, choose MDK Project.
Choose the Start button.
In the next page, enter the basic information of the project and choose the Finish button.
Use the following data:
MDK Template Type | Empty |
---|
MDK Template Type | <Empty> |
Your Project Name | ZSAMComponent |
Your Application Name | ZSAMComponent (auto populated based on Project Name) |
Target MDK Client Version | MDK 6.0+ (For use with 6.0 or later clients) |
Choose a target folder. | /home/user/projects (auto populated based on preferences) |
Hint
After the creating the new project, you can view both projects in the workspace. However, if you only see one project, from the menu choose File → Close Folder. Then, choose Files and folders. Enter /home/user/projects. Choose OK. Choose Open Workspace and choose the default projects workspace.
Once the new project is created in the workspace you see files and folders within.
Add a reference to the standard application.
Choose Application.app
Right click, and from the menu choose Open With → Select Text Editor.
Add the following code:
Maintain the Localization and ReferenceApplications fields as shown in the following image.
Note
When there are no options in the Localization field, yo can skip this entry.
Task 3: Copy the Service Files
The component project uses the same back-end oData service as the SAP Service and Asset Manager project. So, copy the AssetManager.service and OnlineAssetManager.service service files from project SAPAssetManager.
Steps
Copy the AssetManager.service from the SAPAssetManager project to your custom ZSAMComponent.
Expand the SAPAssetManager project.
Locate and open the Services folder.
Right-click the AssetManager.service and choose Copy... or use (Ctrl+C).
Paste (Ctrl+V) the AssetManager.service file into the ZSAMComponent project. Then Sync the Service to download the updated Metadata (Objects).
In the ZSAMComponent project, right-click Services and choose Paste (or Ctrl+V).
Note
If the "right click copy and paste" does not work in your browser, choose Ctrl+C and Ctrl+V.
In the Services folder under the ZSAMComponent project, double-click AssetManager.service.
Note
When you copy the Service, you may be prompted to log in to Cloud Foundry. This information is used by the service to connect to SAP back end to Sync the Metadata (refresh the Object).
Enter the credentials provided by your Trainer (email_address/password).
Choose the Cloud Foundry Target Organization and CF Space. Choose the space based on the group assigned to your ID.
Select the mobile application from the Mobile Services.
Choose Sync Objects to refresh the objects from the service.
In the Refresh Objects pop-up, choose OK.
Note
When you choose Sync Service, the corresponding xml file (with the same name as .service file) is updated. This xml file is the metadata and fetched from the back end.
If for any reason you cannot perform the sync service (connectivity to backend is broken and so on) as a workaround, you can get the metadata file and upload it manually, so that the latest OData Model changes in the back end get reflected in your project.
Copy the OnlineAssetManager.service from the SAPAssetManager project to your custom project ZSAMComponent.
Repeat the steps that you have performed for the AssetManager.service file for the OnlineAssetManager.service file.
Note
The online service has a reference to a Rule /SAPAssetManager/Rules/Common/Passport/GetSAPPassportHeaderValue.js
The Rule in-turn has a reference to a Global /SAPAssetManager/Globals/Passport/ComponentName.global
.
Copy both these files into the corresponding folders of the ZSAMComponent project. You have to create a Passport folder. Once you copy the files, change the reference to the current project (ZSAMComponent).
In ZSamComponent, find the created passport folder under the Rules folder.
Paste a copy of the GetSAPPassportHeaderValue.js from the SAP AssetManager project.
In the code, change the reference to the current project (ZSAMComponent).
In ZSamComponent, find the created passport folder under the Globals folder.
Paste a copy of the ComponentName.global from the SAP AssetManager project.
In the AssetManager.service and OnlineAssetManager.service files, change the reference to the current project (ZSAMComponent).
Task 4: Customize the Overview Page
Steps
Copy the overview page from the SAPAssetManager Component into the ZSAMComponent.
In the SAPAssetManager project, navigate to the Pages folder.
Right-click the Overview page and select Copy.
Navigate to the ZSAMComponent project.
Right-click Services and choose Paste.
Open the Overview.page in the ZSAMComponent project for editing.
To open the layout editor in the Business Application Studio, in the ZSAMComponent project double-click the Overview.page.
Ensure both the left and right pane of the layout editor are enabled.
Choose the Outline tab to switch to the Outline view.
In the layout, use the scrollbar to navigate down to choose the section high_wokrorders. Select the corresponding SectionObjectCollection in the outline.
In the Outline, choose Section Header to change the caption of the High Priority Work Orders section to Active Work Orders.
Choose High_Workorders in the section header.
Note the Syntax of the caption $(L,high_workorders). This syntax is used to display a string from the i18n.properties file. The i18n.properties file is used by translators to convert strings to other languages. During runtime, this string displays the caption in the appropriate language that has been set for the device. As a result, it is good practice to use this file to maintain all strings displayed to the user.
In the Properties tab, change the caption to Active Work Orders.
Edit the Active Work Orders section only to display the workorders that have Started or are On Hold.
In the Outline view of the Overview.page, choose SectionObjectCollection.
In the Properties tab in the Target section, to bring up the Query Options Express Editor, choose the link option next to the QueryOptions field.
The Query Options Express Editor window displays with the default query criteria.
Choose Clear to remove the existing query criteria.
$expand=OrderMobileStatus_Nav&$filter=Priority eq '1' or Priority eq '2'&$orderby=Priority,DueDate,OrderId
Enter the following expression in the Expression Value box:$filter=OrderMobileStatus_Nav/MobileStatus eq 'STARTED' or OrderMobileStatus_Nav/MobileStatus eq 'HOLD'
Choose OK.
The Active Work Orders sections now only display the workorders that are Started or On Hold.
Update the count in the Active Work Orders section as it is still showing the count of the number of the High Priority Work orders.
Right-click the Rules folder and choose New Folder and enter the name WorkOrders.
Right-click the WorkOrders folder and choose New File.
Enter WorkOrdersActiveCount.js in the File Name field.
Double-click WorkOrdersActiveCount.js to edit it.
Create a function as shown in the screenshot and use this code to get the number of Active Work Orders:
12345
export default function WorkOrderActiveCount(context){
return context.count('/SAPAssetManager/Services/AssetManager.service',
'MyWorkOrderHeaders', "$filter=OrderMobileStatus_Nav/MobileStatus eq
‘STARTED’ or OrderMobileStatus_Nav/MobileStatus eq ‘HOLD’");
}
Save the file and close it.
In the Outline.page view, choose sap.mde.SectionFooter (under SectionObjectCollection choose content, and then choose SectionFooter).
In the Properties tab, in the Appearance section, choose the link option next to the AttributeLabel field.
In the Object Browser, double-click the newly created rule.
/ZSAMComponent/Rules/WorkOrders/WorkOrdersActiveCount.js
Choose OK.
Choose File → Save → .
The count now shows the number of work orders that are Started or On Hold.
The count has been updated. However, when we choose the See All navigation link, the Work Order List still shows all of the High Priority Work Orders. Change this so that it shows all Work Orders. For this we overwrite one of the existing standard rules.
Note
In this exercise, we overwrite one of the existing standard rules.In the SAPAssetManager workspace, navigate to Rules → WorkOrder → ListView → WorkOrdersHighPriorityListView.js
Right-click the file and choose Copy(Ctrl+C).
Navigate to ZAMComponent → Rules → WorkOrders. Right-click WorkOrders, and choose Paste (Ctrl+V).
Double-click the newly added file to open it.
On line 7, change the value of the isHighPriorityList property to be false: isHighPriorityList: false,
Hover the mouse over the import statement (Line 1) and verify that it is pointing to the correct path. If necessary, update the logger path ../../../SAPAssetManager/Rules/Log/Logger and this related path refers to "/home/user/projects/SAPAssetManager/Rules/Log/Logger".
From the menu, choose File → Save.
Note the import statement on Line 1. The path to the Logger file is a relative path. ../../log/logger indicates that the Logger file can be found by going two levels above the current directory and then going into the Log directory. This path must change based on the relative path from the current location because the file has been overwritten in the custom project.
So, in this exercise, from the Rules directory in the ZAMComponent project, we must go two levels up and then go into the SAPAssetManager project and get the full path to the logger file. So, the logger path looks like this: ../../../SAPAssetManager/Rules/Log/Logger.
Task 5: Create and Update the SAP CIM File with the Integration Point
You can use the scripts from the ZSAPComponent zip file (ZSAPComponent folder) to perform the steps that require code; or use the following steps.
Steps
Create a new CIM (component integration metadata) file for ZSAMComponent in SAPAssetManager project.
Note
The CIM file is created in the SAPAssetManager
project. The file contains the overrides. When you Deploy and Activate, the MDKWebpackFactory project is ether created (first time) or updated.Right-click SAPAssetManager → Application.app file and choose MDK: New CIM File.
In the CIM Creation page, make selections.
Use the following information:
- Project Name: Choose ZSAMComponent from the Project Name dropdown.
- Application Name: Choose ZSAMComponent from the drop-down menu.
- CIM File Name: ZSAMComponent_ZSAMComponent
- Component Version: nnnn (where nnnn is the product release For Ex: 2205.)
On the Confirmation page, choose Finish.
In the SAPAssetManager, verify that ZSAMComponent_ZSAMComponent.cim has been created.
Create an integration point (page) for the Overview.page.
Use the following information:
Field | Value |
---|
Source | /ZSAMComponent/Pages/Overview.page |
Target | /SAPAssetManager/Pages/Overview.page |
Double-click the ZSAMComponent_ZSAMComponent.cim file.
In the Integration Points section, choose the + icon.
Choose Page.
In the Page Integration Point section, choose the Link icon next to the Source field to open the Object browser.
The Object Category shows Page. Enter Overview in the search field.
From the search results, choose ZSAMComponent(/ZSAMComponent) → Pages → Overview.page.
Choose the Insert button to Inset the result into the Expression box.
Choose OK.
To save the integration point setting, choose the 'Blue Check.'
Similarly, for the Target, locate the /SAPAssetManager/Pages/Overview.page.
From the search results, choose SAPAssetManager(/SAPAssetManager) → Pages → Overview.page.
Choose the Insert button to Inset the result into the Expression box.
Choose OK.
To save the integration point setting, choose the blue Check button.
Create an integration point (rules) for WorkOrdersHighPriorityListView.js.
Use the following information:
Field | Value |
---|
Source | /ZSAMComponent/Rules/WorkOrders/WorkOrdersHighPriorityListView.js |
Target | /SAPAssetManager/Rules/WorkOrders/ListView/WorkOrdersHighPriorityListView.js |
In the Integration Points section, choose the + icon.
Choose Rule.
Repeating the steps for each page, search for WorkOrdersHighPriorityListView choose the Source from ZSAMComponent Project and the Target from SAPAssetManager Project.
Choose File → Save All → .
Note
- We didn’t have to create an Integration Point for the new file WorkOrdersActiveCount.js that was created in the ZSAMComponent project. The integration point is only necessary when the component is overwriting any files in the SAP Service and Asset Manager project.
- The Crew Component also has an Overview page that overrides the Overview page of the SAPAssetManager project. The ZComponent also has the Overview page so this causes a conflict. However, the CIM files are processed in alphabetical order and the last one wins. Therefore, the CIM file of the ZComponent will win and the Overview page of the ZComponent will be displayed in the Mobile Client (that is, you will no longer see the Crew information).
Task 6: MDK Deploy to Mobile Services
Steps
Deploy the Metadata changes to the SAP Business Technology Platform Mobile Services mobile app.
Right-click the SAPAssetManager → Application.app file in the workspace. From the context menu, choose MDK Deploy to Mobile Services.
Accept the default destination (CF_DEST_IAM150_##) and Application Id (com.sap.iam150_##) values entered from the previous deployment.
Result
Once the MDK App is deployed successfully (that is, /MDKWebpackFactory is rebuild and you get the message "(MDK Webpack) Application deployed successfully. Current Revision:<xx>").
On your mobile device, close and relaunch the mobile app.
A pop-up displays with the message: Update (via re-launching the app).Check for Updates. Choose the OK Confirm button to download new version of the app.
After the App definition update, verify that your changes are displayed in the Overview page.
Note
The Active Work Orders shows the number of work orders that are in STARTED or HOLD status.
Task 7: Start a Work Order
Steps
Start a Work Order.
Choose the Work Orders tile in the Overview page.
This opens the work order list page.
In the work order list page, choose a work order you want to start. This opens the work order details page.
Choose the Start Work Order button.
Choose Start. You will notice that the work order status has changed to STARTED.
Navigate back to the Overview page. You now see the work order that you have started under the Active Work Orders.
Result
This feature enables users to quickly launch the active work orders from the overview page without navigating into the work orders list page.