In the previous blog, we examined the features that enable developers to navigate product hierarchies, edit attributes, and create inline BML scripts. In this blog, we will look at the features related to editing Util BML Libraries.
Even though Oracle has a guide for best practices that every CPQ developer should follow, the best practices are not enforced. As a result, it’s easy for developers to write code without following any (or) all of the best practices.
The extension will catch such best practice violations and display them as warnings to the developer so that they can be addressed promptly and have manageable code.
Sometimes, developers follow certain coding practices specific to their organization, which could sometimes violate some of the best practices. For such cases, there is no need to panic; the extension provides a configuration with which each of these best practice violations can be turned on or off based on organization-specific coding practices.
Here is a sample screenshot of the problems window showing some of the best practice violations
But How Does It Do It?
Extension invokes a command line tool that will parse the BML code and provide a list of warnings and errors. The command line tool is built to understand the grammar of the BML language. It validates by traversing the parse tree structure generated based on the grammar. While crossing, it catches all of these warnings and errors. Once the parsing is complete, it returns these errors and warnings to the caller. In our case, the caller is the vscode ide. The IDE now displays all these errors and warnings in the problems view.
Validate BML Script
Everyone makes mistakes, and so do CPQ developers. A developer's mistake can be caught only after a validation call is triggered to the server using the Oracle CPQ toolkit. He/she will have to look at the validation results logs to determine any errors, make the corrections accordingly, and repeat the process of running the validation on the server side and analyzing the results until the code is error-free.
Here is the typical workflow when not using the extension
Here is the typical workflow when using the extension
The extension does the BML script validation on the client side to catch such semantic and/or syntactic errors and display them in the problems window without making any validation calls to the server.
Autocomplete BML Functions
What is the use of having an IDE without an autocomplete feature? We added autocomplete for all Oracle CPQ BML functions with short documentation.
Manage Code Snippets
You might wonder if this is all good, but what if I want to manage custom code snippets? Yes, we have this feature where developers can manage their code snippets and use them in the editor during code completions. For example, the screenshot below shows a snippet named “findInArraySnippet.” When you expand the little arrow at the end, it will display a short description of the snippet and the actual code that will be inserted when this snippet is selected.
Call Hierarchy
In CPQ, reusable code can be used in the form of global util functions. These functions can be referenced from other inline BML scripts or global BML function(s).
The extension provides a quick way to look at the call hierarchy from any BML file. Clicking on the call hierarchy from within a BML file will display the global functions invoked along with global functions invoked from the invoked global function, and so on. Clicking on any global function will open the corresponding BML in a new tab.
Capture Code Execution Timings
As developers, we all know how critical measuring the performance of the code we write is. To do this in BML script, one would capture the timings before and after and then print the time taken as the difference between the two-time entries.
start = getcurrenttimeinmillis();
//execute business logic
end = getcurrenttimeinmillis();
print(“It took “ + (end-start) +” ms ” + “ to complete”);
Trying to find this statement within the log is another challenge altogether. But this code pattern must be repeated wherever we want timings captured. But wait, what if I say you don’t have to write any of this timing code but still get the execution timings for any BML script? The extension will create a copy of the actual BML code, insert the boilerplate timing code, execute the modified code on the server side to capture the timings, and then display the timings overlaid on top of the actual code. Let’s see a screenshot to understand it better.
No timing capture code is involved in the above code, but the timings are displayed after execution. The extension manages this. During execution, the extension will create a copy of the BML code, inject timing capture code, and execute the modified code on the server side. Retrieve the logs, extract the timing metrics from the logs for the executed code, and overlay the metrics above each line ( only on those lines where the execution time is > 0 ms).
Here is the actual flow
Run Unit Tests
When using the Oracle CPQ toolkit, one has to create a zip file with the required source & test files for running the unit tests. Once the test execution is complete, one has to look at the execution results log to see the status of the unit test execution.
This can be done by right-clicking on the BML file and selecting the “Run BML Unit test” option. This will package the needed files, upload to the server for execution, extract the results from the log file, and display them right next to the BML test file.
Call Graph
Generate dynamic visual graphs that map the flow of nested utility calls, linked attributes, and the relationships between configuration rules and their util functions for better debugging and analysis.
The graph can be generated from within any of the util library function. Navigate to any util library function and right click and select “ OE CPQ CoPilot >> Generate Call Graph” option.
This will find all incoming references to this library function and outgoing references to other util library functions that this function invokes. Not just the references to/from util library functions, but also to any configuration rules that reference this library function will also be visible in the graph. Clicking on any node will include all the incoming/outgoing references to the selected node. To remove any node from the graph, just click on the node.
About the Author
Sivaram Balakrishnan
Software Architect
Sivaram Balakrishnan is a Senior Software Architect with extensive experience in designing, developing, and maintaining high-quality software solutions. He is passionate about innovation and continuous improvement, he is dedicated to creating efficient, reliable, and scalable software that meets user needs and aligns with business goals.