Introduction to Web SDK and Odin framework
- A command-line interface (CLI) to create new projects and to do other development-related tasks like building and executing the project;
- A core API without any Angular dependencies that only require RxJS; and
- Angular services for M3-related functions, including executing MI programs and bookmarks, retrieving user context and launching programs in the H5 client.
Setting up the environment
To create and run Web SDK, you need Node Package Manager (NPM). You can download and install npm from the Node.js download page: https://nodejs.org/en/download/. NPM will be installed with Node.js
Tip: To verify that your installation was successful, use the following command (npm -v). If it is installed correctly, this will display the npm version.
Next, we need to install Odin packages. Execute the below command to install Odin CLI globally on your local computer.
Installing Odin globally means you can execute Odin commands from any of your folders. Use the below command to verify the installation.
Development
- Open the Command Prompt window and navigate to the folder where you would like to create the project.
- Execute ‘odin new’ command and answer all the questions. Please refer to the below screen for the wizard of questions.
- Navigate to the project folder in the command line and install dependencies for the application.
- Start the project and access it in a browser using http://localhost:8080.
- You can open the created project using VS (Visual Studio) Code or any other editor and start editing the code.
User context
The web SDK runs within the H5 client and most of the time, we have to access user objects. This can be accessed using the API MNS150/GetUserData, but the Odin framework provides built-in services to access user objects.
The MIService will use and pass the current company as a parameter to the M3 programs, unless specific CONO and DIVI are mentioned in the MIRequest. The following code snippet explains how to access user context. Loading the UserContext as part of the application initialization is recommended rather than calling this multiple times.
Ensure the name adheres to the specified naming convention when selecting a project name. For example, it allows only letters, numbers and dashes; no spaces are allowed.
Here we are not calling MNS150 API explicitly, but the inbuilt user service is calling the API. If you can open the developer tools in the browser, you can notice the service call in the network tab.
Calling M3 APIs
Calling M3 APIs using web SDK is very easy with Odin. We can call get, list and change transactions. By default, the framework will pass the current company and the division as the parameters if the user context has already been retrieved. The below example code will retrieve customer details using CRS610MI/ GetBasicData.
The MI transaction may return a lot of data. Therefore, always specify the output fields to increase performance and reduce bandwidth.
Deployment
- Open the Command Prompt window and navigate to the folder where you would like to create the project.
- Execute ‘odin new’ command and answer all the questions. Please refer to the below screen for the wizard of questions.
- Navigate to the project folder in the command line and install dependencies for the application.
- Start the project and access it in a browser using http://localhost:8080.
- You can open the created project using VS (Visual Studio) Code or any other editor and start editing the code.
Creating shortcut
Use the following steps to create a shortcut in M3:
- Open the program where a shortcut must be created (ex: mms001) and click Shortcuts.
- Add the name and target URL
- Click Add and then Save
- The shortcut will be displayed as shown below
At times you may need to pass a few parameters to the URL. For example, select a style from MMS001 and click on a shortcut to open the selected style information. The following steps allow passing a parameter to an application:
- Open Tools > Link Manager
- Add the Title and click Next
- Add the parameter as shown below:
https://<your-url-here>/mne/apps/tech-talk/#?itno=<MMITNO>
This will pass the selected style number into the field as an input.
Written by:
Mohamed Akbar
Technical Lead, Fortude